.從命令行得到5個(gè)整數(shù),放入一個(gè)整形數(shù)組,然后打印輸出,要求:如果輸入數(shù)據(jù)不為整數(shù),要捕獲Integer.parseInt()長(zhǎng)生的異常,“顯示請(qǐng)輸入整數(shù)”,捕獲輸入?yún)?shù)不足5個(gè)的異常(數(shù)組越界),顯示“請(qǐng)輸入至少5個(gè)整數(shù)”。import?java.util.Scanner;public?class?Text2 { public?static?void?main(String[] args){ System.out.println("請(qǐng)輸入五個(gè)整數(shù):"); try{ int?a=Integer.parseInt(args[0]); int?b=Integer.parseInt(args[1]); int?c=Integer.parseInt(args[2]); int?d=Integer.parseInt(args[3]); int?e=Integer.parseInt(args[4]); } catch(NumberFormatException n){ System.out.println("請(qǐng)輸入整數(shù)"); } catch(ArrayIndexOutOfBoundsException e){ System.out.println("請(qǐng)至少輸入五個(gè)整數(shù)"); } catch(Exception e){ System.out.println(e.getMessage()); } }?}?
幫忙看看哪里不對(duì)
慕粉15937965096
2016-11-03 21:59:43