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。任何人都可以指出错误?我基本上检查数组中没有两个连续的数字是否相同,然后打印相同的数组,但是如果连续两个数字相同,则使用下一个数字的副本。java array outofboundexception
for循环'i
chenchuk
中的ints [i + 1]。既然你现在用ith + 1 –
来检查ith,那么它给了我一个数组转储的东西,但是outofboundException不见了。 – NewProgrammer7