2
我試圖從用戶連續讀取輸入,直到用戶鍵入退出。我正在通過輸入'quit'來測試它,但是console.hasNext()似乎沒有返回false。事實上,程序似乎在第7行(hasNext()行)被阻塞。有任何想法嗎?Java掃描器hasNext()不返回false
boolean bool = true;
while (bool) {
System.out.println("Type 'quit':");
Scanner console = new Scanner(System.in);
if (console.next().equals("quit")) {
System.out.println("You typed quit");
System.out.println("check: " + console.hasNext()); // This line doesnt print
bool = false;
}
}