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();
}
}
想知道如何在完成輸入後終止程序? 由於掃描儀仍然會繼續幾經「回車」假設我要繼續下面的輸入... 我想:如何在輸入完成後終止掃描儀?
if (scan.nextLine() == null) System.exit(0);
和
if (scan.nextLine() == "") System.exit(0);
他們沒有工作....該程序繼續和初始意圖混淆,
非常感謝:) – user2318175 2013-04-25 10:43:53