我在编写java时有这个问题,不知道如何解决它。任何帮助都会很棒。这是我的代码的一部分。错误就在最后。
Scanner scan = new Scanner(System.in);
String name = null;
while (scan.hasNextLine()) {
n = scan.nextInt(); //line 37
m = scan.nextInt();
if (n == -1 && m == -1) {
break;
}
init();
for (int i = 0; i < n; i++) {
name = scan.next();
course.put(name, i);
}
...
p[1] = 1;
for (int i = 2; i <= 12; ++i)
p[i] = p[i - 1] << 1;
input();//line 117
solve();
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:864)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at Graduate.graduateProj.input(graduateProj.java:37)
at Graduate.graduateProj.main(graduateProj.java:117)
答案 0 :(得分:1)
如果您尝试在无法解析为int的字符串上调用InputMismatchException
,则会得到Scanner::nextInt
。