public class ex07_1 {
public static void main(String[] args) {
int[][] bit = {{1, 0, 1, 0, 1, 1, 1, 1},
{1, 0, 0, 0, 0, 0, 1, 1},
{0, 1, 0, 0, 0, 0, 0, 0},
{1, 1, 1, 1, 0, 0, 0, 0},
{1, 0, 1, 1, 1, 0, 0, 1},
{0, 0, 0, 0, 0, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1},
{0, 1, 1, 1, 1, 0, 0, 0}};
for(int width=0; width<bit.length; width++) {
for(int height=0; height<bit[width].length; height++) {
System.out.printf("%d ", bit[width][height]);
}
int rowParity = widthParity(bit[width]);
System.out.printf("%d ",rowParity);
System.out.println();
}
for(int height=0; height<bit[0].length; height++) {
int colParity = heightParity(bit, height);
System.out.printf("%d ", colParity);
}
int totalParity = 0;
for(int width=0; width<bit.length; width++) {
totalParity += widthParity(bit[width]);
}
for(int height=0; height<bit[0].length; height++) {
totalParity += heightParity(bit, height);
}
System.out.printf("%d\n", totalParity%2);
}
public static int widthParity(int[] arr) {
int count = 0;
for(int width : arr) {
if(width == 1) {
count++;
}
}
return count%2;
}
public static int heightParity(int[][] arr, int height) {
int count = 0;
for(int width=0; width<arr.length; width++) {
if(arr[width][height] == 1) {
count++;
}
}
return count%2;
}
}