我是個JAVA初學者,這是我寫的簡易加法
import java.util.Scanner;
public class ab{
public static void main(String args[]){
Scanner cin=new Scanner(System.in);
int a=cin.nextInt(),b=cin.nextInt();
while (a!=-1){
System.out.println(a+b);
a=cin.nextInt();
b=cin.nextInt();
}
}
}
但是提交卻是re.
錯誤說明是
*** 第 1 點 (10%):RE
執行時發生錯誤(code:1)!!
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:817)
at java.util.Scanner.next(Scanner.java:1431)
at java.util.Scanner.nextInt(Scanner.java:2040)
at java.util.Scanner.nextInt(Scanner.java:2000)
at code_97553.main(code_97553.java:8)
*** 第 2 點 (90%):RE
執行時發生錯誤(code:1)!!
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:817)
at java.util.Scanner.next(Scanner.java:1431)
at java.util.Scanner.nextInt(Scanner.java:2040)
at java.util.Scanner.nextInt(Scanner.java:2000)
at code_97553.main(code_97553.java:8)
請問需要如何修改?