在引用初始化数组对象的属性时遇到问题

时间:2015-09-23 00:28:02

标签: arrays multidimensional-array

我试图写一个名为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;

提前致谢!

0 个答案:

没有答案