forked from iRupam/NewtonSchoolInfinityJune21
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrixTranspose.java
More file actions
39 lines (34 loc) · 1.06 KB
/
MatrixTranspose.java
File metadata and controls
39 lines (34 loc) · 1.06 KB
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
35
36
37
38
39
package InfinityJune21.TwoDArray;
public class MatrixTranspose {
public static void main(String[] args) {
int n = 7, m = 3;
int arr[][] = new int[n][m];
int transpose[][] = new int[m][n];
int element = 1;
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
arr[i][j] = element;
element++;
}
}
System.out.println("Original Array: ");
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
System.out.printf("%3d", arr[i][j]);
}
System.out.println();
}
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
transpose[j][i] = arr[i][j];
}
}
System.out.println("Transposed Array: ");
for(int i = 0; i < m; i++) {
for(int j = 0; j < n; j++) {
System.out.printf("%3d", transpose[i][j]);
}
System.out.println();
}
}
}