title: How to find the amount of odd numbers and thee sum of all odd numbers in a inputted 2D array java?
body: <p>I'm trying to find the total amount of odd numbers in a 2D array inputted by the user in java. I'm also trying to find the sum of all those odd numbers. I've figured out how to find the number of odd numbers in a strictly square 2d array (ie. 2x2, 3x3, 4x4, etc) but when I input an array size of for example 2x3 or say 5x6 the output is incorrect. What am I doing wrong?</p>
  
  <pre><code>import java.util.Scanner;
  public class SumOfOdd
  {
      public static void main (String []args)
      {
          Scanner input =  new Scanner (System.in);
          System.out.println("No. of rows");
          int rows = input.nextInt();
          System.out.println("No. of columns");
          int cols = input.nextInt();
  
          int [][] array1 = new int[rows][cols];
          System.out.println("Input array elements");
          for(int row = 0; row &lt; rows; row++)
          {
              for(int col = 0; col &lt; cols; col++)
              {
                  array1[row][col] = input.nextInt();
              }
          }
          int count = 0;
          for(int i = 0; i &lt; array1.length; i++)
          {
              for(int j = 0; j &lt; array1.length; j++)
              {
                  if(array1[i][j] % 2 == 1)
                  {
                      count++;
                  }
              }
          }
          System.out.println("Odd number count = " + count);
      }
  }
  </code></pre>