【发布时间】:2017-11-26 23:42:51
【问题描述】:
这是我的代码的一部分,用于验证输入和循环是否是字符,但是在输入字符时会导致无限循环,但在使用整数时可以正常工作。我不知道是什么导致了无限循环,但我们将不胜感激。
System.out.println("Please type in a mark and enter -1 to end the program");
while (mark != -1) {
if (in.hasNextInt()) {
mark = in.nextInt();
}
else {
System.out.println("Please input an integer: ");
}
【问题讨论】:
-
System.out.println("Please input an integer: "); in.nextLine();
标签: java loops validation infinite-loop