Question
What is the error in my java program that the largest row output is equal to the largest column so it's not correct?? 1 /*
What is the error in my java program that the largest row output is equal to the largest column so it's not correct??
1 /* Program: Largest row and column 2 Book: introduction to java programming 10th edition 3 Page:309 4 Exercise 8.10 5 6 Description: Write a program that randomly fills in 0s and 1s into a 4-by-4 matrix, 7 prints the matrix, and finds the first row and column with the most 1s. 8 Here is a sample run of the program: 9 0011 10 0011 11 1101 12 1010 13 The largest row index: 2 14 The largest column index: 2 15 16 */ 17
import java.util.Random; public class LargRowColumn{ public static void main(String[] args){ // Display welcome message System.out.println(" "+ "*** Welcome to Largest Row & Coloumn Program***"); // Setup a 4x4 matrix int n =4; int[][]matrix=new int[n][n]; for(int i=0; i< n;i++){ // outer loop for(int j=0; j< n;j++){ // inner loop matrix[i][j]= (int)(Math.random()*2); System.out.print(matrix[i][j]+" "); } // end of inner loop System.out.println(); } // end of outer loop System.out.println(); // check columns int columnSum = sumColumn(matrix,0); int columnIndex=0; for(int i=0; i RESULT EXAMPLE: *** Welcome to Largest Row & Column Program *** 1 0 1 1 0 0 0 1 0 1 0 1 1 0 0 0 The largest column index is on: 3 ...... That's means column #4 The largest row index is on : 3 ...... That means row #4
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started