Java Program to Display Transpose Matrix Last Updated : 07 Jan, 2021 Comments Improve Suggest changes 9 Likes Like Report Transpose of a matrix is obtained by changing rows to columns and columns to rows. In other words, transpose of A[][] is obtained by changing A[i][j] to A[j][i]. Approach: Create a 2-D Array.Insert the values in the array by running two nested loops. The outer ith loop will go till the no.of rows and the inner jth loop will run till the number of columns.For displaying the transpose of the matrix, run the same loop as explained in the above step but print the a[j[i] th element every time we are traversing inside the loop. Example: Java // Java Program to Display Transpose Matrix import java.util.*; public class GFG { public static void main(String args[]) { // initialize the array of 3*3 order int[][] arr = new int[3][3]; System.out.println("enter the elements of matrix"); int k = 1; // get the elements from user for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { arr[i][j] = k++; } } System.out.println("Matrix before Transpose "); // display original matrix for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { System.out.print(" " + arr[i][j]); } System.out.println(); } System.out.println("Matrix After Transpose "); // transpose and print matrix for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { System.out.print(" " + arr[j][i]); } System.out.println(); } } } Outputenter the elements of matrix Matrix before Transpose 1 2 3 4 5 6 7 8 9 Matrix After Transpose 1 4 7 2 5 8 3 6 9 Comment M mukulsomukesh Follow 9 Improve M mukulsomukesh Follow 9 Improve Article Tags : Java Technical Scripter Java Programs Technical Scripter 2020 Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings8 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java9 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages7 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java4 min readJava Comparator Interface4 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java7 min readFile Handling in Java4 min readJava Method References9 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management4 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read Like