forked from shikaruki/Hactoberfest2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RotateBy90Degree.java
72 lines (47 loc) · 1.22 KB
/
RotateBy90Degree.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import java.util.Scanner;
public class RotateBy90Degree {
public static void Display(int [][] a)
{
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[0].length; j++) {
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int size = scn.nextInt();
int [][] image = new int[size][size];
for (int i = 0; i < image.length; i++) {
for (int j = 0; j < image[0].length; j++) {
image[i][j] = scn.nextInt();
}
}
// Display(image);
// Transpose Of A Image
for (int i = 0; i < image.length; i++) {
for (int j = i; j < image[0].length; j++) {
int temp = image[i][j];
image[i][j] = image[j][i];
image[j][i] = temp;
}
}
// System.out.println();
// Display(image);
for (int i = 0; i < image.length; i++) {
int li = 0;
int ri = image.length-1;
while(li < ri)
{
int temp = image[i][li];
image[i][li] = image[i][ri];
image[i][ri] = temp;
li++;
ri--;
}
}
// System.out.println();
// Display(image);
}
}