title: Getting a logic error while trying to get the average of a 2D array
body: <p>In this program, I have to fill a 2D array with user-inputted values and find the average of all the array's elements. However, the program instead finds the average by dividing the sum by the number of rows instead of the number of numbers. I tried setting average to a 2D array in itself but it only recognized one reference instead of both of them. Halp</p>
  
  <pre><code>public static void main(String[] args) {
      int[][] array = createArray();
  
      System.out.printf("The average of this array is " + "%.2f", average(array));
  }
  
  public static int[][] createArray() {
      Scanner sc = new Scanner(System.in);
      System.out.print("Enter the number of rows: ");
      int numRows = sc.nextInt();
      System.out.print("Enter the number of columns: ");
      int numColumns = sc.nextInt();
  
      int[][] array = new int[numRows][numColumns];
  
      System.out.println("Enter " + array.length + " rows and " + array[0].length + " columns");
  
      for (int row = 0; row &lt; array.length; row++)
          for (int column = 0; column &lt; array[0].length; column++)
              array[row][column] = sc.nextInt();
      return array;
  }
  
  public static double average(int[][] a) {
      int sum = 0;
      double average = 0;
      for (int row = 0; row &lt; a.length; row++) {
          for (int column = 0; column &lt; a[row].length; column++) {
              sum += a[row][column];
          }
              average = sum / a.length; 
      }
  
      return average;
  }
  </code></pre>
  
  <p>}</p>