title: Multiplying 2d arrays(matrices) in java
body: <p>My goal is to print out the Matrix when the two arrays are multiplied together.  What am I doing wrong with this code?  How do I get it so that it prints out the matrix?  (Sorry I do not know what other details i should provide and I cannot submit this post unless I add more detail).   </p>
  
  <pre><code>public class Matrices {
  static int mRows = 0;
  static int mCol = 0;
  static int nRows = 0;
  static int nCol = 0;
   public static int[][] multiplyMatrices(int[][] m, int[][] n){
      mRows = m.length;
      mCol = m[0].length;
      nRows = n.length;
      nCol = n[0].length;
      if(canBeMultiplied(m,n) == false){
          throw new IllegalArgumentException("Cannot multiply arrays");
      }
      int[][] answer = new int[mRows][nCol];
      for(int i = 0; i &lt; mRows; i++){
          for(int j = 0; j &lt; nCol; j++){
              for(int k = 0; k &lt; mCol; k++){
                  answer[i][j] += m[i][k] * n[k][j];
              }
          }
      }
      return answer;
  }
  
  public static boolean canBeMultiplied(int[][] m, int[][]n){
      mRows = m.length;
      mCol = m[0].length;
      nRows = n.length;
      nCol = n[0].length;
      if(nRows == mCol){
          return true;
      }
      return false;
  }
  
  public static void main(String[] args) {
      int[][] temp1 = {{1,2,3},{4,5,6}};
      int[][] temp2 ={{1},{2},{3}};
      for(int i = 0; i &lt; mRows; i++){
          for(int j = 0; j &lt; nCol; j++){
              System.out.print(multiplyMatrices(temp1,temp2)[i][j]);
          }
                      System.out.print("\n");
      }
  
  }
  }
  </code></pre>
  
  <p>Thanks for your help.</p>