-1
e.g操作)接近掃描器(System.in)後,創建掃描儀(System.in),但不能正確
public void a(){
Scanner input = new Scanner(System.in);
String a = input.nextLine();
....
input.close();
}
public void b(){
Scanner scan = new Scanner(System.in);
int b = scan.nextInt();
....
scan.close();
}
此掃描儀不能正常工作。 但刪除close()後,它可以正常工作。
我猜原因是'System.in'有問題。
請給我答案。
謝謝
+)首先調用input.nextLine()的(),然後調用scan.nextInt(b)中()。 我有錯誤,例如NoSuchElementException。
*試圖掃描儀已經關閉將導致IllegalStateException後執行搜索操作進行更換。*是你得到了什麼? – nullpointer