forked from pikachu-17/java-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTranspose_of_matrix.java
More file actions
32 lines (31 loc) · 880 Bytes
/
Transpose_of_matrix.java
File metadata and controls
32 lines (31 loc) · 880 Bytes
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
public class Transpose_of_matrix {
public static void main(String[] args) {
int[][] matrix = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
int i, j = 0;
for (i = 0; i <= matrix.length; i++) {
for (j = 0; j <= matrix[i].length; j++) {
int temp = i;
i = j;
j = temp;
}
}
System.out.println(matrix[i][j]);
}
}
//actual solution
//class Solution {
// public int[][] transpose(int[][] matrix) {
// int m,n;
// int res[][]= new int[matrix[0].length][matrix.length];
// for(int i =0 ;i<matrix.length; i++){
// for(int j=0;j<matrix[0].length; j++){
// res[j][i]=matrix[i][j];
// }
// }
// return res;
// }
//}