我想让用户输入一行文本,只要x
不等于numOfContestans
. 当我运行代码时,我得到一个InputMismatchException
. 有谁知道如何解决这个错误?
try {
int numOfContestants = scan.nextInt();
int problems = scan.nextInt();
scan.nextLine();
int x = 0;
while (x != numOfContestants) {
String input = scan.nextLine();
x++;
}
System.out.println(problems);
} catch(InputMismatchException e) {
System.out.println("Something went wrong");
}