-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransposematrix.java
More file actions
43 lines (34 loc) · 1.14 KB
/
Copy pathtransposematrix.java
File metadata and controls
43 lines (34 loc) · 1.14 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
40
41
42
43
// Online Java Compiler
// Use this editor to write, compile and run your Java code online
class Main {
public static void main(String[] args) {
int matrix[][]={{1,2,3},{4,5,6},{7,8,9}};
for(int i=0;i<matrix.length;i++)
{
for(int j=i+1;j<matrix[i].length;j++){
int temp=0;
temp=matrix[i][j];
matrix[i][j]=matrix[j][i];
matrix[j][i]=temp;
}
}
int left=0;
int right=matrix.length-1;
for(int i=0;i<matrix.length;i++){
while(left<right){
int temp=0;
temp=matrix[i][left];
matrix[i][left]=matrix[i][right];
matrix[i][right]=temp;
left++;
right--;
}
}
for(int i=0;i<matrix.length;i++){
for(int j=0;j<matrix[i].length;j++){
System.out.println(matrix[i][j]+ " ");
}
System.out.println();
}
}
}