-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathArrayRotation.java
50 lines (42 loc) · 1.1 KB
/
ArrayRotation.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
public class ArrayRotation
{
public static void main(String[] args)
{
int[][] array = {{0,1},
{1,0}} ;
int[][] target = {{1,0},
{0,1}} ;
rotated(array);
System.out.print("Modified matrix is \n");
for (int i = 0; i < array.length; i++)
{
for (int j = 0; j < array.length; j++)
System.out.print(array[i][j] + " ");
System.out.print("\n");
}
check(array, target);
}
public static void rotated(int[][] matrix)
{
for (int i = 0; i < matrix.length; i++)
{
for (int j = i+1; j < matrix.length; j++)
{
matrix[i][j]^=matrix[j][i];
matrix[j][i]^=matrix[i][j];
matrix[i][j]^=matrix[j][i];
}
}
}
public static void check(int[][] array_1, int[][] array_2)
{
for (int i = 0; i < array_1.length; i++)
{
for (int j = 0; j < array_2.length; j++)
{
if (array_1[i][j] == array_2[j][i])
break ;
}
}
}
}