Question
JAVA- How do I edit this code to combine all the methods into one main method? Sample input/output below: import java.util.Scanner; public class Prog7 {
JAVA- How do I edit this code to combine all the methods into one main method? Sample input/output below:
import java.util.Scanner;
public class Prog7 { public static void main(String[] args) Scanner reader = new Scanner(System.in);
// reading dimension int n = reader.nextInt();
// creating 2D array int [][] matrix = new int[n][n];
// reading in matrix int i=0;
while(reader.hasNext()){ int j = 0;
while(j
j++; } i++; } // array to store row and column sum
int rowSum[] = new int[n]; int colSum[] = new int[n];
// row sum
for (int r = 0; r
for (int c = 0; c
sum += matrix[r][c];
} rowSum[r] = sum; }
// col sum
for (int c = 0; c
for (int r = 0; r
colSum[c] = sum; }
// display
for (int r = 0; r
for (int c = 0; c
System.out.println(" : "+rowSum[r]); }
System.out.println("---------------------------");
for(int c=0; c } public static void averageEachRow(int[][] matrix) { int row = matrix.length; int col = matrix[0].length; for (int i = 0; i for (int j = 0; j System.out.println("Average of " + (i + 1) + " row: " + String.format("%.3f", sum /col)); } } public static void averageEachCol(int[][] matrix) { int row = matrix.length; int col = matrix[0].length; for (int i = 0; i for (int j = 0; j System.out.println("Average of " + (i + 1) + " column: " + String.format("%.3f", sum /row)); } }
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