我正在尝试启动此编码,但遇到以下错误消息:
线程“ main”中的异常java.util.NoSuchElementException在 java.util.Scanner.throwFor(Scanner.java:862)在 java.util.Scanner.next(Scanner.java:1485)在 java.util.Scanner.nextInt(Scanner.java:2117)在 java.util.Scanner.nextInt(Scanner.java:2076)在 Analysis.main(Analysis.java:17)
import java.util.Scanner;
public class Analysis
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int passes = 0;
int failures = 0;
int studentCounter = 0;
while (studentCounter <= 10)
{
System.out.print("Enter result (1 = pass, 2 = fail): ");
int result = input.nextInt();
if (result == 1)
passes = passes + 1;
else
failures = failures + 1;
studentCounter = studentCounter + 1;
}
System.out.printf("Passed: %d%nFailed: %d%n", passes, failures);
if (passes > 8)
System.out.println("Bonus");
}
}
有人可以告诉我解决方法吗? 谢谢。