-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlippingImage.java
More file actions
44 lines (36 loc) · 1011 Bytes
/
FlippingImage.java
File metadata and controls
44 lines (36 loc) · 1011 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
35
36
37
38
39
40
41
42
43
44
package Array;
/**
* Author - archit.s
* Date - 15/08/18
* Time - 12:29 AM
*/
public class FlippingImage {
public int[][] flipAndInvertImage(int[][] A) {
int row = A.length;
for(int i=0;i<row;i++){
int column = A[i].length;
for (int j=0;j<(column+1)/2;j++){
int leftSide = A[i][j];
int rightSide = A[i][column-j-1];
A[i][j] = rightSide ^ 1;
A[i][column - j -1] = leftSide ^ 1;
}
}
return A;
}
public static void main(String[] args) {
int[][] a = {
{1},
{1, 1},
{0, 0, 0},
};
final int[][] image = new FlippingImage().flipAndInvertImage(a);
for(int i=0;i<image.length;i++){
for(int j=0;j<image[i].length; j++){
System.out.print(image[i][j] + " ");
}
System.out.println("\n");
}
System.out.println();
}
}