Description
int [][] matrix = new int [4][4];
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
System.out.println(matrix[i][j]);
This is what I entered but just got a bunch of zeroes. I need the matrix to be 4x4 with the numbers 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16. When I run the program it needs to show the matrix, "Sum of row 1:", "Sum of row 2:" (as well as row 3 and 4), "Sum of column 1:" (and the rest of the columns), and sum of diagonals.
Explanation & Answer
Thank you for the opportunity to help you with your question!
you should write this program :
to fulll the matrix :
Scanner input = new Scanner(System.in);
int [][] matrix = new int [4][4];
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
System.out.println("Enter the vlaue : ");
matrix[i][j] = input.nextLine();
}}
and you should write this to output the value :
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
System.out.print(" "+matrix[i][j]);
}
System.out.println(" ");
}
and you wiill get it as you want ok
just ask if you need something
Good Luck
Review
Review
24/7 Homework Help
Stuck on a homework question? Our verified tutors can answer all questions, from basic math to advanced rocket science!
Similar Content
Related Tags
My Brilliant Friend
by Elena Ferrante
A Wrinkle as Time
by Madeleine L'Engle
The Power of Habit - Why We Do What We Do in Life and Business
by Charles Duhigg
The Fault in Our Stars
by John Green
Rules Of Civility
by Amor Towles
Moby Dick
by Herman Melville
Silas Marner
by George Eliot
The Mayor of Casterbridge
by Thomas Hardy
The Catcher in the Rye
by J. D. Salinger