Skip to content

Commit c79a09d

Browse files
authored
Create Java Program to transpose matrix
1 parent 667f6f3 commit c79a09d

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

Java Program to transpose matrix

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
public class MatrixTransposeExample{
2+
public static void main(String args[]){
3+
//creating a matrix
4+
int original[][]={{1,3,4},{2,4,3},{3,4,5}};
5+
6+
//creating another matrix to store transpose of a matrix
7+
int transpose[][]=new int[3][3]; //3 rows and 3 columns
8+
9+
//Code to transpose a matrix
10+
for(int i=0;i<3;i++){
11+
for(int j=0;j<3;j++){
12+
transpose[i][j]=original[j][i];
13+
}
14+
}
15+
16+
System.out.println("Printing Matrix without transpose:");
17+
for(int i=0;i<3;i++){
18+
for(int j=0;j<3;j++){
19+
System.out.print(original[i][j]+" ");
20+
}
21+
System.out.println();//new line
22+
}
23+
System.out.println("Printing Matrix After Transpose:");
24+
for(int i=0;i<3;i++){
25+
for(int j=0;j<3;j++){
26+
System.out.print(transpose[i][j]+" ");
27+
}
28+
System.out.println();//new line
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)