Skip to content

Commit e098222

Browse files
authored
Transpose_of_Matrix.java
1 parent e334644 commit e098222

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Transpose_of_Matrix.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
}}

0 commit comments

Comments
 (0)