title: How to calculate the average of each row and column in array
body: <p>So yesterday I asked for help, and a lot of people helped me out with my question, I really appreciated that guys. However, I run into a second problem of my homework, and I have been trying to solve it from this morning, and now it's like almost 2AM in the morning, and I'm not gonna sleep until I solve this problem. I'm not going to lie, so this is my homework to test the basic knowledge of mine. I know I make major mistakes somewhere, so please help me to point them out, so I can fix them. Thank you</p>
  
  <p>The output should be:</p>
  
  <pre><code>  1, 2, 3, ave=2
    4, 5, 6, ave=5
  aver=2.5, 3.5, 4.5
  </code></pre>
  
  <p>This is my current code:</p>
  
  <pre><code>import java.util.Scanner;
  public class Ex {
      public static void main(String[] args) 
      { 
          Scanner input = new Scanner(System.in);
  
          System.out.print("Enter a number for rows: ");
          int rows = input.nextInt();
  
          System.out.print("Enter a number for columns: ");
          int columns = input.nextInt();
  
          int[][] array = new int[rows][columns];
  
          System.out.println("Enter the numbers in array: ");
  
          for(int i=0 ; i&lt;rows ; i++)
          {
              for(int j=0 ; j&lt;columns ; j++)
              {
                  array[i][j] = input.nextInt();
              }
          }
          for(int i=0 ; i&lt;rows ; i++)
          {
              for(int j=0  ; j&lt;columns ; j++)
              {
                  System.out.print(array[i][j] + " , ");
              }
              System.out.println("\n");    
          }  
      }
      double averageRow(int[][] array) {
          int rowTotal = 0;
          double average = 0;
  
          for (int rows = 0; rows &lt; array.length; rows++) {
              for (int columns = 0; columns &lt; array[rows].length; columns++) {
                  rowTotal += array[rows][columns];
              }
              average = rowTotal / array[rows].length;
              System.out.println(average);
              rowTotal = 0;
          }
          return rowTotal;    
      }
      double averageColumn(int[][] array) {
          int columnTotal = 0;
          double average = 0;
  
          for (int columns = 0; columns &lt; array.length; columns++) {
              for (int rows = 0; rows &lt; array[columns].length; rows++) {
                  columnTotal += array[rows][columns];
              }
              average = columnTotal / array[columns].length;
              System.out.println(average);
              columnTotal = 0;
          }
          return columnTotal;  
      }
  }
  </code></pre>