-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranposematrix.java
34 lines (30 loc) · 1.02 KB
/
tranposematrix.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import java.util.*;
public class tranposematrix {
public static void main(String[] args) {
System.out.println("Printing Matrix without transpose:");
int matrix[][]= {{1,2,3}, {4,5,6},{5,6,7}};
int row=3, column=3;
//print matrix
for(int i=0;i<matrix.length;i++){
for(int j=0;j<matrix[0].length;j++){
System.out.print(matrix[i][j] + " ");
}
System.out.println();
}
//transpose matrix
int[][] transmatrix=new int[column][row];
for(int i=0;i<row;i++){
for(int j=0;j<column;j++){
transmatrix[j][i]=matrix[i][j];
}
}
System.out.println("Printing Matrix After Transpose:");
//print transpose matrix
for(int i=0;i<matrix.length;i++){
for(int j=0;j<matrix[0].length;j++){
System.out.print(transmatrix[i][j] + " ");
}
System.out.println();
}
}
}