第一個heres th代碼段。數組越界但只有一個提前
double array [][]= new double [10000][11];
double test=333;
array[0][0]=300;
array[0][1]=400;
array[0][2]=500;
array[0][3]=600;
array[0][4]=700;
array[0][5]=200;
array[0][6]=200;
array[0][7]=200;
array[0][8]=200;
array[0][9]=200;
array[0][10]=200;
int tiere =0;
int i=0;
for (int stelle=0;array[i][stelle]!=0;stelle++){
tiere++;
}
System.out.println(tiere);
if (tiere<11) test=1;
else test=array[0][0];
System.out.println(test);
}
}
當你看到我拿出多少用線陣中擁有,如果它的10把它給我,值了。但如果它的11這麼最大有一個失敗「數組越界」最新錯誤?
盯着'array [i] [stelle]!= 0; stelle ++' –
如果數組有'11'元素,最後一個索引是'10','11'超出範圍,數組索引從'0'開始。 – julekgwa
你是否期望索引11應該是有效且可訪問的?爲什麼? – Tom