所以我正在使用这个编译器站点处理我的代码:https : //www.tutorialspoint.com/compile_java_online.php
当我运行我的代码时,它出现了这个错误:
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:862)
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 WorkingWithLoops.main(WorkingWithLoops.java:22)
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
import java.util.Scanner;
public class WorkingWithLoops {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int negative = 0, positive = 0, sum = 0, value;
System.out.print("Enter a value: ");
value = input.nextInt();
while (value != 0){
if (value < 0){
negative++;
}
else {
positive++;
}
sum += value;
System.out.print("\nEnter a value: ");
value = input.nextInt(); …Run Code Online (Sandbox Code Playgroud)