title: Java matrix multiplication
body: <p>I'm writing a program for class where we hard code matrices in a driver class and put the matrix operations in a matrix class. I'm running into an issue where I get the error:</p>
  <pre><code>Exception in thread &quot;main&quot; java.lang.ArrayIndexOutOfBoundsException: 2
  </code></pre>
  <p>I'm pretty sure that it's the second for loop but I can't think of what range to do to refer to the columns of the hard coded matrix in the driver class.</p>
  <p><code>row</code> and <code>col</code> are both instantiated in the <code>Matrix</code> class and I fixed the <code>j++</code> but it still gives the same error even when I'm doing a <code>1x2</code> multiplied by a <code>2x3</code>, for example</p>
  <pre class="lang-java prettyprint-override"><code>public Matrix mult(Matrix m) {
      // TODO: Multiply the two matrices, store the value
      // in a new matrix and return that matrix
      Matrix m5 = new Matrix(new int[row][col]);
      for (int i = 0; i &lt; row; i++) {
          for (int j = 0; j &lt; m.myMatrix[0].length; j++) {
              for (int k = 0; k &lt; col; k++) {
                  m5.myMatrix[i][j] += myMatrix[i][k] * m.myMatrix[k][j];
              }
          }
      }
      return m5;
  }
  </code></pre>