title: 2D Array Average (Java)
body: <p>I need this method to take the middle columns of the 2D array that was made/changed in other methods, compute the average of each row (excluding the 0 index and last index), place that average in the last column of the row, then go down to the next row and repeat until there are no more rows. Basically a setup of 2 rows and 3 columns will actually have 5 columns as seen below.</p>
  
  <pre><code>   Weight  Grade1  Grade2  Grade3  Average
    ----------------------------------------
  1|  4.0     5.0     5.0     5.0    -999.0  
  2|  5.0     10.0    10.0    10.0   -999.0  
  </code></pre>
  
  <p>the method needs to take the Grade scores, find their average, then replace the -999.0 with the average, and then do the same for the next rows that exist(size defined by user input in another method). Here is my code for the method, I know I am fairly close, but I am making a few mistakes somewhere.</p>
  
  <pre><code>public static double[][] computeCategoryAverages(double[][] scoreArray){
      for(int i = 0; i &lt; scoreArray.length; i++){
          double sum = 0;
          int numOfAssign = 0;
          if(i == 0){
              System.out.println("The Average for the first category: ");
              for(int j = 1; j &lt; scoreArray[0].length-1; j++){
                  sum = sum + scoreArray[0][j];
                  numOfAssign++;
              }
              double average = sum / numOfAssign;
  
              for(int k = 0; k &lt; scoreArray.length; k++){
                  //sum = sum + scoreArray[i][j];
                  //noOfAssign++;     
                  scoreArray[k][scoreArray[k].length-1] = average;  
              }
          }
          else{
              System.out.println("The Average for the next category: ");
              for(int j = 1; j &lt; scoreArray[0].length-1; j++){
                  sum = sum + scoreArray[i][j];
                  numOfAssign++;
              }
              double average = sum / numOfAssign;
              for(int k = 0; k &lt; scoreArray.length; k++){
                  //sum = sum + scoreArray[i][j];
                  //noOfAssign++;     
                  scoreArray[k][scoreArray[k].length-1] = average;  
              }
          }
      }
      return scoreArray;
  }
  </code></pre>