title: Computing sum of elements in array
body: <p>I have a class <code>Mold</code> with the following constructor </p>
  
  <pre><code>public Mold(int[][] mold){
      this.mold = mold; 
    }
  </code></pre>
  
  <p>I also have a method <code>sum()</code> which looks like this:</p>
  
  <pre><code>public int sum(){
      int sum = 0;
      for( int i = 0; i &lt;matrix.length; i++) {
        sum += matrix[i][i];
      }
      return sum;
    }
  </code></pre>
  
  <p>What I am trying to do is compute the sum of all the elements in <code>Mold</code> but I am unsure as to what to put in the <code>sum += matrix[i][i];</code> part in place of 'i'. I might even be doing it the complete wrong way. I have been stuck on this for a while and I cannot seem to figure it out. </p>
  
  <p>An example of the output I would like to get is: <code>int[][] test1 = { { 10, 5 }, { 2, 8 } };</code> should give 25 one the sum method has been applied. </p>
  
  <p>If someone could push me in the right direction that would be great! 
  Many thanks, </p>