Answer to Question #322566 in Java | JSP | JSF for Nhm

Question #322566

Write a Java program to obtain transpose of a 4 x 4 matrix. The Transpose of the matrix is obtained by exchanging the elements of each row. With the elements of the corresponding column. 


1
Expert's answer
2022-04-02T09:58:59-0400
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner in = new Scanner(System.in);

        int[][] arr = {{1, 2, 3, 4}, {1, 2, 3, 4}, {1, 2, 3, 4}, {1, 2, 3, 4}};
        int[][] arrT = new int[4][4];


        for(int i = 0; i < 4; i++){
            for(int j = 0; j < 4; j++){
                arrT[j][i] = arr[i][j];
            }
        }

        for(int i = 0; i < 4; i++){
            for(int j = 0; j < 4; j++){
                System.out.print(arrT[i][j] + " ");
            }
            System.out.println("");
        }

    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS