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

Java programming *8.23 ( Game: find the flipped cell ) Suppose you are given a 6

ID: 668906 • Letter: J

Question

Java programming

*8.23 (Game: find the flipped cell) 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)

Explanation / Answer

import java.util.Scanner; public class Exercise_08_23 { public static void main(String[] args) { // Prompt the user to enter a 6-by-6 matrix System.out.println("Enter a 6-by-6 matrix row by row:"); int[][] matrix = getMatrix(); // Find the first row r and first column c where // the even number of the 1s property is violated int row = oddRow1s(matrix); int column = oddColumn1s(matrix); // Display the flipped cell if (row < 0 || column < 0) System.out.println("No cell has been flipped"); else { System.out.println( "The flipped cell is at (" + row + ", " + column + ")"); } } /** getMatrix initializes and returns a 6 x 6 matrix of user input */ public static int[][] getMatrix() { // Create a Scanner Scanner input = new Scanner(System.in); // Create a 6 x 6 matrix int[][] m = new int[6][6]; for (int i = 0; i
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