【发布时间】:2017-06-06 06:23:54
【问题描述】:
我意识到 hasNext() 用于检查是否会有下一个输入,但我的 hasNext 出于某种原因提示输入。这是我的代码:
Scanner sc = new Scanner(System.in);
while (!sc.hasNext("quit")) {
System.out.println("Type anything other than quit to keep inputting. ");
sc.nextLine();
}
我的程序立即执行的操作是让我输入一些内容(在提示输入之前),然后弹出“输入除退出以外的任何内容”的提示,并且程序正常运行。但是,我不想要第一个空白输入。为什么会弹出这个问题,我该如何解决?
【问题讨论】: