title: Java loop through array of array
body: <p>Suppose I have an array of an array: </p>
  
  <pre><code>double[][] img = new double[row][col];
  </code></pre>
  
  <p>and i want to loop through img in a 2x2 block... example: </p>
  
  <pre><code>2,  4, 31, 31   
  3,  3, 21, 41
  1,  2, 10, 20
  3,  2, 20, 30
  </code></pre>
  
  <p>then you start by looking at the first 2x2 sub-array (from the top-left)</p>
  
  <pre><code>2,  4
  3,  3
  </code></pre>
  
  <p>We then look at the next 2x2 block</p>
  
  <pre><code>31,  31
  21,  41
  </code></pre>
  
  <p>other blocks would be 1,2,3,2 and 10,20,20,30...</p>
  
  <p>How do make a loop so it goes through like this? Essentially I am doing this so I can find the average of the values in the block, and replace each element in the array by that average.</p>