我试图写一个名为Matrix的类,它由二维数组组成。但是,我在主类中引用其他初始化的Matrix对象时遇到问题。特别是在我的添加方法中。
public class Matrix {
private int rows;
private int cols;
private double [][] m;
public Matrix (int r, int c){
rows = r;
cols = c;
m = new double [r][c];
for (int i = 0; i < rows; i++){
for (int j = 0; j < cols; j++){
m [i][j] = 0;
}
}
}
public Matrix add (Matrix m1) {
Matrix m2 = new Matrix(rows, cols);
for (int i = 0; i < this.rows; i++){
for (int j = 0; j < this.cols; j++){
m[i][j] + m1[i][j] = m2[i][j];
}
}
return m2;
}
IDE在网上说 m [i] [j] + m1 [i] [j] = m2 [i] [j]; 那个&#34;需要数组,但Matrix找到了&#34;
提前致谢!