-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path14thJune(II).java
More file actions
34 lines (31 loc) · 949 Bytes
/
Copy path14thJune(II).java
File metadata and controls
34 lines (31 loc) · 949 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 RotateMatrix {
static void rotate(int[][] a){
int [][] arr = new int[a[0].length][a.length];
for(int i =0; i<a.length; i++){ // transpose logic
for(int j = 0; j<a[0].length; j++){
arr[j][i]=a[i][j];
}
}
for(int[] c : arr){
for( int b : c){
System.out.print(b+",");
}System.out.println();
}
// now swapping logic
for(int[] b : arr){
for(int i = 0 , j = a[0].length-1; i<a.length/2 ; i++ ,j-- ){
int temp = b[i];
b[i] = b[j];
b[j] = temp;
}
for(int c : b){
System.out.print(c+",");
}
System.out.println();
}
}
public static void main(String[] args) {
int[][] a = {{1,2,3},{4,5,6},{7,8,9}};
rotate(a);
}
}