異常catch疑問(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;
請(qǐng)問(wèn)加下劃線(xiàn)的語(yǔ)句是什么意思?
2016-08-05
這樣的一段局部代碼看不出來(lái)
2016-08-04
System.in是標(biāo)準(zhǔn)輸入設(shè)備。 Scanner是JAVA流里面的一個(gè)輸入類(lèi)。
scanner console = new Scanner(System.in)就是從標(biāo)準(zhǔn)輸入設(shè)備(一般是鍵盤(pán))中讀取數(shù)據(jù)。