title: A matrix class in java
body: <p>I need to create a matrix class, which has 2 constructors, and a method which does a filter average to a number with the numbers around it in the matrix.</p>
  
  <p>Here is what I came up with, but when I try to compile it, I get an error:
  "array expected, Matrix found".</p>
  
  <p>Help please !</p>
  
  <pre><code>/**
  * This class represents a two dimensional Matrix 
  * 
  */
  public class Matrix
  {
  private int[][] _matrix;
  
  /**
   * Constructs a Matrix from a two-dimensional array; the dimensions as well as the values of this Matrix will be the same as the dimensions and values of the two-dimensional array.
   */
  public Matrix(int[][] array)
  {
      for (int i=0; i &lt; array.length;i++)
          for (int j=0; j &lt; array[i].length;j++)
              _matrix[i][j] = array[i][j];
  }
  
  /**
   * Constructs a size1 by size2 Matrix of zeroes.
   */
  public Matrix(int size1, int size2)
  {
      for (int i=0; i &lt; size1;i++)
          for (int j=0; j &lt; size2;j++)
              _matrix[i][j]=0;
  }
  
  /**
   * Calculates and returns a copy of this Matrix after it has been filtered from noise. All pixels are represented by a number 0-255 inclusive. 
   * 
   * @return a copy of this Matrix after it has been filtered from noise
   */
  public Matrix imageFilterAverage()
  {
      Matrix newMatrix = new Matrix(_matrix);
  
  
      for (int i=0; i &lt; _matrix.length;i++)
          for (int j=0; i &lt; _matrix[i].length;j++)
              newMatrix[i][j] =  _matrix[i-1][j-1] + _matrix[i-1][j] + _matrix[i-1][j+1] + _matrix[i][j-1] + _matrix[i][j] + _matrix[i][j+1] + _matrix[i+1][j-1] + _matrix[i+1][j] + _matrix[i+1][j+1];
  }
  
  
  }
  </code></pre>
  
  <p><strong>Edit</strong></p>
  
  <p>Hey guys, thanks for the help. Now I'm trying to make a toString method, That will print the matrix, with tab between the numbers, but after the last number in the last row, there won't be a tab.
  Can't really get it working, don't know how to return it. But here is what I came up with so far:</p>
  
  <pre><code> public String toString()
   { 
   for (int i=0; i &lt; _matrix.length; i++) { 
      for (int j=0; j &lt; _matrix[i].length; j++) 
         if (j == (_matrix[i].length - 1)) 
                System.out.print(_matrix[i][j]); 
         else System.out.print(_matrix[i][j] + "\t"); 
       System.out.println(); 
   } 
  
  
  }
  </code></pre>