4x4 matrix in java programming

User Generated

tergn1995

Programming

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. 

User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

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 


Please let me know if you need any clarification. I'm always happy to answer your questions.


Anonymous
Very useful material for studying!

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Related Tags