以下代码
class Matrix {
private int[][] matrice;
public Matrix(int[][] matrice){
this.matrice = matrice;
}
public int rows(){
return matrice.length;
}
public int columns(){
return matrice[0].length;
}
public Matrix add(Matrix secondMatrix){
int[][] sum = new int[matrice.rows()][matrice.columns()]; //ERROR
Matrix result = new Matrix(sum);
return result;
}
}
当我声明“sum”数组时返回两个错误,因为它“找不到符号方法行()”或“方法列()”。可能是什么问题?
答案 0 :(得分:1)
应该改变这个
自:
int[][] sum = new int[matrice.rows()][matrice.columns()];
要:
int[][] sum = new int[secondMatrix.rows()][secondMatrix.columns()];