forked from ghostmkg/programming-language
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transposeOfAMatrix.java
38 lines (32 loc) · 1005 Bytes
/
transposeOfAMatrix.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
35
36
37
38
public class transposeOfAMatrix {
public static void main(String[] args) {
int[][] Array = {
{ 5, 6, 1, 2 },
{ 3, 8, 7, 0 },
{ 10, 9, 8, 6 },
{ 1, 3, 5, 9 }
};
transform(Array);
print(Array);
}
public static void transform(int[][] A) {
int N = A.length;
for (int row = 0; row < N; row++) {
for (int col = 0; col < N; col++) {
if (row != col && row<col) {
int temp = A[row][col];
A[row][col] = A[col][row];
A[col][row] = temp;
}
}
}
}
public static void print(int[][] A) {
for (int row = 0; row < A.length; row++) {
for (int col = 0; col < A[0].length; col++) {
System.out.print(A[row][col] + " ");
}
System.out.println();
}
}
}