2015-09-28 257 views
-5
public static void main(String args[]) 
{ 
    Calculation C=new Calculation(); 
    int i; 
    for(i=5;i>=0;i--) 
    { 
     C.m[i]=Integer.valueOf(args[i]);   
     //assignment of command line arguments with the array//   
    } 
    C.display(); 
} 

這個封裝類這給出的誤差「異常在線程‘主要’java.lang.ArrayIndexOutOfBoundsException:5」的命令行參數的輸入作爲10 20 30 40 50 60 請幫我什麼錯與for循環

+0

什麼樣的類是''Calculation''?從錯誤消息結束,Calculation類的數組「m」的大小小於5.不能訪問索引5處的元素,因爲索引從0開始,第5個元素將在索引4處。 – rbialon

+0

沒有足夠的信息告訴 – edtheprogrammerguy

+1

循環假定兩個數組('args []'和'Cm []')至少有6個元素。看起來至少有一個沒有。 – David

回答

0

C中的數組m少於6個元素。在第一次循環執行時,您正嘗試訪問數組中的第六個元素C.m [5]。 args []也是如此。