BlueJ keeps writing I have an error in the line
int[] row = arr[i];
and I don't have any other idea how to put the array in the i row of arr into the array row.
the problem is in the method specialAll()
.
public static boolean isIn(int num, int dig) {
int is;
boolean bool = false;
while (num != 0) {
is = num % 10;
if (is == dig) {
bool = true;
}
num = num / 10;
}
return bool;
}
public static boolean specialArr(int[] arr) {
int i, dig, num;
boolean bool = true;
for (i = 0; i < arr.length - 1; i++) {
num = arr[i + 1];
dig = (arr[i]) % 10;
if (!isIn(num, dig)) {
bool = false;
}
}
return bool;
}
public static boolean specialAll(int[][] arr) {
int i;
boolean bool = true;
for (i = 0; i < arr[0].length; i++) {
int[] row = arr[i];
if (!specialArr(row)) {
bool = false;
}
}
return bool;
}
when I run the method and input as arr the matrix
{ { 12, 525, 53, 8367, 17, 471 }, { 12, 525, 53, 8365, 152, 22 } }
which is supposed to return true, the program stops in the middle and writes:
`java.lang.ArrayIndexOutOfBoundsException: 2 at Excersise10.specialAll(Excersise10.java:42)