Question: 5 - ( Largest row and column ) : Write a program that randomly fills in 0 s and 1 s into a 5 -

5-(Largest row and column): Write a program that randomly fills in 0 s and 1 s into a 5-by-5 matrix, prints the matrix, and finds the first row and column with the most 1 s . Here is a sample run of the program:
01101
01011
10010
11111
00101
The largest row index: 3
The largest column index: 4
Write the code here and attach a screenshot of the output.
import java.util.*;
public class Helloworld {
public static void main(String[]
args){
int[][] matrix = new int[5][5];
Random rand = new Random();
for (int i=0;i5;i++)
for (int j=0;j5; j++)
{
matrix[i][j]=
rand.nextInt (2) ;
}
}
for (int i=0;i5;i++{
for (int j=0;j5;j++)
{
System.out.print(matrix[i][j]);
}
System.out.println();
}
int maxRowCount =-1,
maxRowIndex =-1;
for (int i=0;i5;i++){
int rowCount =0;
for (int j=0;j5;j++)
{
if (matrix[i][j]==1){ rowCount++;
5 - ( Largest row and column ) : Write a program

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!