我创建了一个方法,该方法需要检查多维数组的范围,并确保二维数组中的每个值都小于或等于数组的长度。
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;
}
但是,我收到的错误如下:
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
也许对于第一个错误,我需要获取数组值而不是比较数组?没有把握..