第一章作業參考
參考作業的最后幾行中的“console = new Scanner(System.in);“的作用是什么,為什么刪掉后在輸入書本序號時輸入字母就會陷入死循環。
private static int inputCommand(){
int command;
try {
command = console.nextInt();
return command;
} catch (Exception e) {
//若輸入字符型或者字符串,則拋出異常,捕獲該異常,拋出”錯誤命令異常“
console = new Scanner(System.in);
//返回-1
return -1;
}
2016-05-12
我也遇到了這個問題,刪掉
private static int inputCommand(){
int command;
try {
command = console.nextInt();
return command;
} catch (Exception e) {
//若輸入字符型或者字符串,則拋出異常,捕獲該異常,拋出”錯誤命令異常“
console = new Scanner(System.in);
//返回-1
return -1;
}
這一段代碼,然后將主函數中的“int command =inputCommand();”改為:int command =
將“int index = inputCommand();”改為:int index = console.nextInt();
2016-05-08
這個應該是當你拋出異常了,直接還可以在控制臺進行輸入,不然的話,程序就終結了。。。。
2016-04-18
你刪掉這里還可以輸入么,厲害。小白有點看不懂。