title: Finding rows and columns with the maximum number of 1s in a randomly generated binary matrix
body: <p>The output of this program works fine. But there's one thing I've not been able to implement. In some cases, I don't have a row or column with the highest number of 1s. Sometimes I have 2 or more rows/columns which have the same "HIGHEST" number of ones. But my program only returns 1 row/column. </p>
  
  <p>I want a case whereby If i have more than 2 rows/columns with the same highest number of 1s. Both rows will be displayed. e.g. "Row(s) with the most 1's: 1,2" or if it's a column it can say "Row(s) with the most 1's: 1,2".</p>
  
  <p>Please I need help with this. I'm stuck.</p>
  
  <pre><code>import java.util.Random; 
      import java.util.Scanner; 
  
      public class LargestRowColumn 
      { 
         // declare a 2 dimensional array or an array of arrays 
         private static int[][] randArray; 
  
         public static void main(String[] args) 
         { 
          do
          {
            // Create a scanner to get Input from user. 
            Scanner scanner = new Scanner(System.in); 
            System.out.print("\nEnter the array size n:"); 
            int rows = scanner.nextInt(); 
            int cols = rows;
  
            randArray = new int[rows][cols]; 
  
            // loop through the number of rows in thw array 
            for (int i = 0; i &lt; randArray.length; i++) 
            { 
               // loop through the elements of the first array in the array 
               for (int j = 0; j &lt; randArray[0].length; j++) 
               { 
                  // set a random int 0-1 to the array 
                  randArray[i][j] = getRandomInt(0, 1); 
                  // print the number just assigned 
                  System.out.print(randArray[i][j]); 
               }
               // make a linebreak each row. 
               System.out.println();
            }
            System.out.print("Row(s) with the most 1's: " + scanRow(randArray) + "\n");
            System.out.print("Columns(s) with the most 1's: " + scanColumn(randArray) + "\n"); 
          }
          while(true);   
         } 
  
         // quick method I made to get a random int with a min and max 
         public static int getRandomInt(int min, int max) 
         { 
            Random rand = new Random(); 
            return rand.nextInt(max-min+1)+min; 
         }
  
  
         public static int scanRow(int[][] array) 
         {
            int result = -1;
            int highest = -1;
  
            for (int row = 0; row &lt; array.length; row++)// Here we are about start looping through the matrix values
            {
               int temp = 0; // Setting the first index to 0.
               for (int col = 0; col &lt; array[row].length; col++)// 
               {
                  //Assign current location to temporary variable
                  temp = temp + array[row][col];
               }
  
               if (temp &gt; highest)
               {
                  highest = temp;
                  result = row + 1;
               }
            }
            return result;
         } // end of row method
  
         private static int scanColumn(int[][] array) 
         {
              int result = -1;
              int highest = -1;
  
              // declare and initialize the variable(here you've 'created' it, to then call it on if statement)
              int col = 0;
  
              for (int row = 0; row &lt; array.length; row++)
              {
                  int temp = 0;
                  //declare the variable in the for loop
                  for (col = 0; col &lt; array[row].length; col++) 
                  {
                      //Assign current location to temp variable
                      temp = temp + array[row][col];
                  }
  
                 if (temp &gt; highest) 
                 {
                     highest = temp;
                   result = col;
                 }
              }
              return result;
         }
  
  
      }
  </code></pre>