title: Summing up each row and column in Java
body: <pre><code>/*
   * Programmer: Olawale Onafowokan
   * Date: February 6, 2014
   * Purpose: Prints the row and column averages
   */
  class Lab4 {
      public static void main(String[] args) {
          int [][] scores = {{ 20, 18, 23, 20, 16 },
              { 30, 20, 18, 21, 20 },
              { 16, 19, 16, 53, 24 },
              { 25, 24, 22, 24, 25 }};
          outputArray(scores);
      }
  
      public static void outputArray(int[][] array) {
          int sum= 0;
          int rowSize = array.length;
          int columnSize = array[0].length;
          System.out.println("rows=" + rowSize + "cols=" + columnSize);
  
          for (int i = 0; i &lt; array.length; i++) {
              for (int j = 0; j &lt; array[0].length; j++) {
                  sum += array[i][j];
              }
              System.out.println("Print the sum of rows = " + sum);
          }
          for (int i = 0; i &lt; array.length; i++) {
              sum = 0;
              sum = sum + array[i][j];
              // It is telling me the j can't be resolved
          }
      }
  }
  </code></pre>
  
  <p>The program prints out:</p>
  
  <pre><code>rows=4cols=5
  Print the sum of rows = 612
  Print the sum of rows = 20358
  Print the sum of rows = 652058
  Print the sum of rows = 20866609
  </code></pre>
  
  <p>I don’t understand why it isn't adding up the numbers correctly. I am trying to add up each row and column. I am not even sure where these numbers are coming from.</p>