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