0
public static int[] squeeze(int[] ints) {
int i;
int[] temp;
temp = new int[100];
for (i = 0; i < ints.length; i++) {
if (ints[i] != ints[i + 1]) {
temp[i] = ints[i];
}
else{
while (ints[i] != ints[i + 1]) {
i++;
}
temp[i] = ints[i];
}
}
return temp;
}
このコードを実行すると、arrayOutOfBoundExceptionが返されます。どのようなボディでもエラーを指摘できますか?私は基本的に配列内の2つの連続する数字が同じでないことを確認していて、同じ配列を印刷しますが、2つの連続したものが同じであれば次の数字のコピーで印刷します。java配列outofboundexception
ints[i + 1]
が存在しないため
ループ 'i
chenchuk
です。あなたはiith + 1 –
でiをチェックしているので、配列のダンプを何か与えても、outofboundExceptionはなくなります。 – NewProgrammer7