Question

In: Computer Science

I need the Java Code and Flowchart for the following program: Suppose you are given a...

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)

Solutions

Expert Solution

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
      
      
    }}


Related Solutions

In Java I need a Flowchart and Code. Write the following method that tests whether the...
In Java I need a Flowchart and Code. Write the following method that tests whether the array has four consecutive numbers with the same value: public static boolean isConsecutiveFour(int[] values) Write a test program that prompts the user to enter a series of integers and displays it if the series contains four consecutive numbers with the same value. Your program should first prompt the user to enter the input size—i.e., the number of values in the series.
I need a java flowchart diagram for the following code: import java.util.*; public class Main {...
I need a java flowchart diagram for the following code: import java.util.*; public class Main {    public static void main(String[] args) {    Scanner sc=new Scanner(System.in);           System.out.print("Enter the input size: ");        int n=sc.nextInt();        int arr[]=new int[n];        System.out.print("Enter the sequence: ");        for(int i=0;i<n;i++)        arr[i]=sc.nextInt();        if(isConsecutiveFour(arr))        {        System.out.print("yes the array contain consecutive number:");        for(int i=0;i<n;i++)        System.out.print(arr[i]+" ");   ...
I need to make this into a Java Code: Write a program that prompts the user...
I need to make this into a Java Code: Write a program that prompts the user for a double value representing a radius. You will use the radius to calculate: circleCircumference = 2πr circleArea = πr2 sphereArea = 4πr2 sphereVolume = 43πr3 You must use π as defined in the java.lang.Math class. Your prompt to the user to enter the number of days must be: Enter radius: Your output must be of the format: Circle Circumference = circleCircumference Circle Area...
Please I can get a flowchart and a pseudocode for this java code. Thank you //import...
Please I can get a flowchart and a pseudocode for this java code. Thank you //import the required classes import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class BirthdayReminder {       public static void main(String[] args) throws IOException {        // declare the required variables String sName = null; String names[] = new String[10]; String birthDates[] = new String[10]; int count = 0; boolean flag = false; // to read values from the console BufferedReader dataIn = new BufferedReader(new...
I need a full java code. And I need it in GUI With the mathematics you...
I need a full java code. And I need it in GUI With the mathematics you have studied so far in your education you have worked with polynomials. Polynomials are used to describe curves of various types; people use them in the real world to graph curves. For example, roller coaster designers may use polynomials to describe the curves in their rides. Polynomials appear in many areas of mathematics and science. Write a program which finds an approximate solution to...
I needv pseudocode and a flowchart for the following java code public class AcmePay { public...
I needv pseudocode and a flowchart for the following java code public class AcmePay { public static void main(String[] args) throws Exception { Scanner scanner = new Scanner(System.in); int hours, shift, retirement = 0; do { System.out.print("Enter the number of hours worked (>0): "); hours = scanner.nextInt(); } while (hours <= 0); do { System.out.print("Enter shift [1 2 or 3]: "); shift = scanner.nextInt(); } while (shift < 1 || shift > 3); if (shift == 2 || shift ==...
Please can I get a flowchart and pseudocode for this java code. Thank you. TestScore.java import...
Please can I get a flowchart and pseudocode for this java code. Thank you. TestScore.java import java.util.Scanner; ;//import Scanner to take input from user public class TestScore {    @SuppressWarnings("resource")    public static void main(String[] args) throws ScoreException {//main method may throw Score exception        int [] arr = new int [5]; //creating an integer array for student id        arr[0] = 20025; //assigning id for each student        arr[1] = 20026;        arr[2] = 20027;...
Please can I kindly get a flowchart for this java code. Thank you. //import the required...
Please can I kindly get a flowchart for this java code. Thank you. //import the required classes import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class BirthdayReminder {       public static void main(String[] args) throws IOException {        // declare the required variables String sName = null; String names[] = new String[10]; String birthDates[] = new String[10]; int count = 0; boolean flag = false; // to read values from the console BufferedReader dataIn = new BufferedReader(new InputStreamReader( System.in));...
I need a java code Write a simple program to prompt the user for a number...
I need a java code Write a simple program to prompt the user for a number between 1 and 12 (inclusive) and print out the corresponding month. For example:   The 12th month is December. Use a java "switch" statement to convert from the number (1-12) to the month. Also use a "do while" loop and conditional checking to validate that the number entered is between 1 and 12 inclusive and if not, prompt the user again until getting the correct...
I need original java code that completes this program and gets it to print out results...
I need original java code that completes this program and gets it to print out results just like in the example. Also please upload answer in a word document format only. Implement both linear search and binary search, and see which one performs better given an array 1,000 randomly generated whole numbers (between 0-999), a number picked to search that array at random, and conducting these tests 20 times. Each time the search is conducted the number of checks (IE...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT