【发布时间】:2014-01-20 17:52:36
【问题描述】:
我目前正在编程挑战网站上做问题 110106。我在下面文件中的第二个 000 上收到 NoSuchElementException。
下面是我的代码,任何帮助都会很棒。
1
299
492
495
399
492
495
399
283
279
689
078
100
000
000
000
这是一个例子:
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() {
}
}
【问题讨论】:
-
请正确缩进您的代码。没有人会照原样阅读它。
-
请说明您的目标是什么。该算法可能不是答案的正确解决方案。
-
他们教你如何在编程挑战中compare strings?