title: Sum of elements in ragged array
body: <p>I am writing a code that computes the sum of all elements in the array <code>Volt</code>. Here is my code so far:</p>
  
  <pre><code>public class Volt{
    int[][] volt;
  
    public Volt(int[][] volt){
      this.volt = volt; 
    }
  
    public int sum(){
      int sum = 0;
      for( int i = 0; i &lt;volt.length; i++) {
        for( int r = 0; r &lt;volt.length; r++){
        sum += volt[i][r];
        }
      }
      return sum;
    }
  
    public static void main(String[] args){
      int[][] a1 = { { 10, 5 }, { 2, 8 } };
      Volt m1 = new Volt(a1);
      System.out.println(m1.sum());
  
    }
  }
  </code></pre>
  
  <p>However, I would like to make it work even if the <code>volt</code> matrix is ragged, with not all rows containing the same number of columns. I did quite a bit of research to get the the point I am at now but what I have now might need changing. I'd appreciate some help :) 
  Thanks! </p>