I created a method that needs to check the range of a multidimensional array and make sure each value in the 2D array is smaller than or equal to the length of the array.
public static boolean method(int[][] solution){
//check rows for 1-N
for (int i=0; i < solution.length; i++){
if (solution[i] > solution.length)
return false; //check rows
}
//check columns for 1 - N
for (int j = 0; j<solution.length; j++){
//get a column in the one dimensional array
int[] column = new int[solution.length];
for (int i=0; i < solution.length; i++){
column[i] = solution[i][j];
}
if (column[i] > solution.length)
return false; //check columns
}
return true;
}
However, the errors I receive are follows:
Program.java:99: error: bad operand types for binary operator '>'
if (solution[i] > solution.length)
^
first type: int[]
second type: int
Program.java:110: error: cannot find symbol
if (column[i] > solution.length)
^
symbol: variable i
location: class Program
2 errors
Perhaps for the first error i need to get the array value instead of comparing the array? Not sure..