-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquestion37.java
More file actions
34 lines (30 loc) · 932 Bytes
/
question37.java
File metadata and controls
34 lines (30 loc) · 932 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
33
34
public class question37 {
public static void main(String[] args) {
int[][] matrix = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
int n = matrix.length;
for(int i = 0; i < n; i++){
for(int j = i; j < n; j++){
int tamp = matrix[i][j];
matrix[i][j] = matrix[j][i];
matrix[j][i] = tamp;
}
}
for(int i = 0; i < n ; i++){
for(int j = 0; j<n / 2; j++){
int temp = matrix[i][j];
matrix[i][j] = matrix[i][n - 1 -j];
matrix[i][n-1-j] = temp;
}
}
for(int i = 0; i < n; i++){
for(int j=0; j < n; j++){
System.out.print(matrix[i][j]+ " ");
}
System.out.println();
}
}
}