Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Suppose you are given a 6-by-6 matrix filled with 0s and 1s. All rows and all co

ID: 3928094 • Letter: S

Question

Suppose you are given a 6-by-6 matrix filled with 0s and 1s. All rows and all columns 3 have an even number of 1s. Let the user flip one cell (i.e., flip from 1 to 0 or from 0 to 1) 4 and write a program to find which cell was flipped. Your program should prompt the user 5 to enter a 6-by-6 array with 0s and 1s and find the first row r and first column c where 6 the even number of the 1s property is violated (i.e., the number of 1s is not even). The 7 flipped cell is at (r, c).

Using the following template:

public static void main(String[] args) {
Scanner input = new Scanner(System.in);

System.out.println("Enter a 6 by 6 matrix row by row:");
int[][] matrix = new int[6][6];

Explanation / Answer

Hi, Please find my code.

Please let me know in case of any issue:

import java.util.Scanner;

public class MatrixProgram {

  

   public static void main(String[] args) {

Scanner input = new Scanner(System.in);

  

System.out.println("Enter a 6 by 6 matrix row by row:");

int[][] matrix = new int[6][6];

  

// taking input

System.out.println("Enter inout sunch way that all row and column contains even number of 1's");

for(int i=0; i<6; i++){

   System.out.println("Enter 6 number (0/1) for row "+(i+1));

   for(int j=0; j<6; j++){

       matrix[i][j] = input.nextInt();

   }

}

  

// flip on cell

  

//.......

// finding row with odd number of rows

int row = 0;

int count = 0;

for(int i=0; i<6; i++){

   // getting count of current row

   count = 0;

   for(int j=0; j<6; j++){

       count += matrix[i][j];

   }

   // if this row contains odd number of 1's, then stop

   if(count %2 == 1){

       row = i;

       break;

   }

}

  

// finding column with odd number of 1's

int column = 0;

  

for(int i=0; i<6; i++){

   // getting count of current row

   count = 0;

   for(int j=0; j<6; j++){

       count += matrix[j][i];

   }

   // if this column contains odd number of 1's, then stop

   if(count %2 == 1){

       column = i;

       break;

   }

}

System.out.println("flipped at cell at ("+row+" "+column+")");

   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote