.從命令行得到5個整數(shù),放入一個整形數(shù)組,然后打印輸出,要求:如果輸入數(shù)據(jù)不為整數(shù),要捕獲Integer.parseInt()長生的異常,“顯示請輸入整數(shù)”,捕獲輸入?yún)?shù)不足5個的異常(數(shù)組越界),顯示“請輸入至少5個整數(shù)”。import?java.util.Scanner;public?class?Text2 { public?static?void?main(String[] args){ System.out.println("請輸入五個整數(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("請輸入整數(shù)"); } catch(ArrayIndexOutOfBoundsException e){ System.out.println("請至少輸入五個整數(shù)"); } catch(Exception e){ System.out.println(e.getMessage()); } }?}?
幫忙看看哪里不對
慕粉15937965096
2016-11-03 21:59:43