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;
}
When I run this code, it gives me arrayOutOfBoundException. Can any body point the error? I am basically checking that no two consecutive numbers in an array are the same and then printing the same array but with a copy of the next number if two consecutive are same.
i< ints.length-1. Since you are checking ith with ith+1