In: Computer Science
I need the Java Code and Flowchart for the following program:
Suppose you are given a 6-by-6 matrix filled with 0s and 1s. All
rows and all columns have an
even number of 1s. Let the user flip one cell (i.e., flip from 1 to
0 or from 0 to 1) and write a
program to find which cell was flipped. Your program should prompt
the user to enter a 6-by-6
array with 0s and 1s and find the first row r and first column c
where the even number of the
1s property is violated (i.e., the number of 1s is not even). The
flipped cell is at (r, c).
Here is a sample run:
Enter a 6-by-6 matrix row by row:
1 1 1 0 1 1
1 1 1 1 0 0
0 1 0 1 1 1
1 1 1 1 1 1
0 1 1 1 1 0
1 0 0 0 0 1
The flipped cell is at (0, 1)
import java.util.Scanner; //importing scanner
class
class matrix{
public static void main(String...args){
int
i,j;
//variables declaration ,this variables are used in loops
int
row=0;
//declaring rownumber(which row has odd 1s)
int
col=0;
//declaring colnumber(which column has odd 1s)
Scanner input=new
Scanner(System.in); //creating object of scanner class
int[][] array=new
int[6][6];
//declaring 2 dimentional array of size 6*6
for(i=0;i<6;i++){System.out.println("enter
"+i+"row");
for(j=0;j<6;j++){
array[i][j]=input.nextInt();}}
//this loop is for taking input values into 2-dimentional
array
System.out.println("matrix is");
for(i=0;i<6;i++){
//outerloop for row_number
for(j=0;j<6;j++){
//innerloop for col_number
System.out.print(array[i][j]+" ");} //printing
2-dimentional array with values
System.out.println();}
for(i=0;i<6;i++){ //outerloop for
row_number
int
count=0;
//initializing count=0
for(j=0;j<6;j++){ //innerloop for
col_number
if(array[i][j]==1){
count++;}} //increamenting
count if the row has 1.
if(count%2==1){ //if row has odd
no.of 1's
row=i;
//make row=i(problem occured at row_number i)
break;}}
// break the loop
for(i=0;i<6;i++){ //outerloop for
col_number
int
count=0;
//initializing count=0
for(j=0;j<6;j++){ //innerloop for
row_number
if(array[j][i]==1){
count++;}}
//increamenting count if the col has 1.
if(count%2==1){ //if col
has odd no.of 1's
col=i;
//make col=i(problem occured at col_number i)
break;}}
// break the loop
System.out.print("The flipped cell is at
("+row+","+col+")"); //printing
cell position
}}