From b148940c13d0bb97b26d5b9e1ee6122cd8c64f35 Mon Sep 17 00:00:00 2001 From: avenger1810 <73022980+avenger1810@users.noreply.github.com> Date: Wed, 21 Oct 2020 23:06:52 +0530 Subject: [PATCH] Create Transpose of matrix --- Transpose of matrix | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Transpose of matrix diff --git a/Transpose of matrix b/Transpose of matrix new file mode 100644 index 0000000..0cc2dcc --- /dev/null +++ b/Transpose of matrix @@ -0,0 +1,30 @@ +public class MatrixTransposeExample{ +public static void main(String args[]){ +//creating a matrix +int original[][]={{1,3,4},{2,4,3},{3,4,5}}; + +//creating another matrix to store transpose of a matrix +int transpose[][]=new int[3][3]; //3 rows and 3 columns + +//Code to transpose a matrix +for(int i=0;i<3;i++){ +for(int j=0;j<3;j++){ +transpose[i][j]=original[j][i]; +} +} + +System.out.println("Printing Matrix without transpose:"); +for(int i=0;i<3;i++){ +for(int j=0;j<3;j++){ +System.out.print(original[i][j]+" "); +} +System.out.println();//new line +} +System.out.println("Printing Matrix After Transpose:"); +for(int i=0;i<3;i++){ +for(int j=0;j<3;j++){ +System.out.print(transpose[i][j]+" "); +} +System.out.println();//new line +} +}}