title: finding the sum of a 2D array in java
body: <p>I'm new to java and I have to find the sum of a 2D array but my code simply won't compile.  I keep getting the errors :</p>
  
  <p>3 errors found:</p>
  
  <pre><code>File: C:\Users\Brett\Documents\DrJava\Matrix.java  [line: 9]
  Error: length cannot be resolved or is not a field
  File: C:\Users\Brett\Documents\DrJava\Matrix.java  [line: 10]
  Error: The type of the expression must be an array type but it resolved to int
  File: C:\Users\Brett\Documents\DrJava\Matrix.java  [line: 15]
  Error: The constructor Matrix(int[][]) is undefined
  </code></pre>
  
  <p>I have no idea how to fix them, thanks in advance for the help!</p>
  
  <pre><code>public class Matrix {
    int[] matrix;
    Matrix(int[] matrix) {
      this.matrix = matrix;
    }
    int sum() {
      int sum = 0;
      for (int i = 0; i &lt; matrix.length; i++)
        for (int j = 0; j &lt; matrix[i].length; j++)
        sum += matrix[i][j];
      return sum;
    }
    public static void main(String[] args) {
      int[][] a1 = { { 1, 2 }, { 3, 4 } };
      Matrix m1 = new Matrix(a1);
      System.out.println(m1.sum());
    }
  }
  </code></pre>