【发布时间】:2020-08-26 11:59:46
【问题描述】:
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
try {
while (scan.hasNextLine()){
String line = scan.nextLine().toLowerCase();
System.out.println(line);
}
} finally {
scan.close();
}
}
只是想知道在完成输入后如何终止程序? 由于假设我要继续输入输入,几次“Enter”后扫描仪仍会继续... 我试过了:
if (scan.nextLine() == null) System.exit(0);
和
if (scan.nextLine() == "") System.exit(0);
他们没有工作....程序继续并与初衷相悖,
【问题讨论】:
标签: java