I am currently doing Problem 110106 from the programming challenges website. I am getting NoSuchElementException
on the second 000 in the file below.
Below that is my code any help would be great.
1
299
492
495
399
492
495
399
283
279
689
078
100
000
000
000
Here's example:
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.NoSuchElementException;
import java.util.Scanner;
public class Problem110106 {
int mainCounter = 0;
int array[] = new int[10];
public static void main(String[] args) throws FileNotFoundException, NoSuchElementException {
// TODO Auto-generated method stub
Problem110106 problem = new Problem110106();
problem.start();
}
public void start() throws FileNotFoundException, NoSuchElementException {
Scanner input = new Scanner(new BufferedReader(new FileReader("text.txt")));
int numTestCases = Integer.parseInt(input.nextLine().trim());
System.out.println(numTestCases);
String blank = input.nextLine();
System.out.println(blank);
while (input.hasNext()) {
int num = Integer.parseInt(input.next());
if (input.next() == "") {
} else {
int first = num / 100;
int second = (num / 10) % 10;
int third = (num % 10);
System.out.println(first);
System.out.println(second);
System.out.println(third);
switch (first) {
case 0:
break;
case 1:
break;
case 2:
set(first, second, third);
break;
case 3:
add(first, second, third);
break;
case 4:
multiply(first, second, third);
break;
case 5:
set(first, second, third);
break;
case 6:
add(first, second, third);
break;
case 7:
multiply(first, second, third);
break;
case 8:
set2(first, second, third);
break;
}
}
}
}
public void set(int first, int second, int third) {
array[second] = third;
mainCounter++;
// System.out.println("got here");
}
public void add(int first, int second, int third) {
array[second] = array[second] + third;
mainCounter++;
}
public void multiply(int first, int second, int third) {
array[second] = array[second] * third;
mainCounter++;
}
public void set2(int first, int second, int third) {
// array[second] =
}
public void goTo() {
}
}