Hello everyone,
I am brand new to the forum as well as brand new to Java. I am taking a class and so far have been able to figure everything out until now. Basically, I need to write a program that accepts a n x n matrix that will total and display the sum of each row and column. First, the user inputs the matrix size (row and columns are the same so only 1 input is needed at this point). We need nested loops in order to populate the matrix, a method that displays the matrix as well as a method that displays the sums of the rows and columns. The program should run in a loop so that the user can do it again and exception handling is required. I won't have an issue with the loop or the exception handling as so far we have done this before and I have a basic understanding of how to do this. My issue is simply the array. Here is what the output should look like:
Enter number of rows & columns (they will be the same): 3
Row 1, Column 1: 1
Row 1, Column 2: 2
Row 1, Column 3: 9
Row 2, Column 1: 0
Row 2, Column 2: 1
Row 2, Column 3: 2
Row 3, Column 1: 0
Row 3, Column 2: 7
Row 3, Column 3: 1
You Entered the Following Matrix:
1 2 9
0 1 2
0 7 1
The sum of row 1 is 12
The sum of row 2 is 3
The sum of row 3 is 8
The sum of column 1 is 1
The sum of column 2 is 10
The sum of column 3 is 12
I am really lost here and I would appreciate some help if anybody is able to figure this out. Thanks a bunch!
And this is what I have so far (albeit very little):
import java.util.Scanner; //Begin Class Main public class Main { //Begin Main Method public static void main(String[] args) { Scanner input = new Scanner (System.in); System.out.print("Enter the number of rows & columns (they will be" + "the same): "); int arraySize = input.nextInt(); } //End Main Method } //End Class Main