1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
MrRissso [65]
3 years ago
8

Problem: you need to write a code that read 2 array of size 10x10 of zero and ones that represent black

Computers and Technology
1 answer:
castortr0y [4]3 years ago
3 0

Answer:

import java.util.Scanner;

import java.lang.*;

public class Main

{

       //variables declared static; to be used inside main()

       static int err;

    static int size=10;

    //arrays declared static; to be used inside main()

       static int[][] white = new int[size][size];

       static int[][] black = new int[size][size];        

   //method to recognize any errors in the image    

   static int recognition(int[][] img)

   {

       //variable to indicate any error

       int notImage=0;

       if(img[1][1]==0)

       {

           for(int l=0;l<size; l++)

           {

               for(int k=0;k<size; k++)

               {

                   if(img[l][k]!=0)

                       notImage++;

               }

           }

       }

       else

       {

           for(int l=0;l<size; l++)

           {

               for(int k=0;k<size; k++)

               {

                   if(img[l][k]!=1)

                       notImage++;

               }

           }

       }

       if(notImage!=0)

           return -1;

       else    

           return 0;

   }

public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

 System.out.println("Enter the elements for 2d black array of size 10(enter 0): ");

 for(int l=0;l<size; l++)

       {

           for(int k=0; k<size; k++)

           {

               white[l][k]=sc.nextInt();    

           }

       }

 System.out.println("Enter the elements for 2d white array of size 10(enter 1): ");

 for(int l=0;l<size; l++)

       {

           for(int k=0; k<size; k++)

           {

               black[l][k]=sc.nextInt();    

           }

       }

 err = recognition(white);

 if(err==-1)

     System.out.println("White image has errors.");

 else    

     System.out.println("White image does not has errors.");

 

    err = recognition(black);

 if(err==-1)

     System.out.println("Black image has errors.");

 else    

     System.out.println("Black image does not has errors.");

}

}

OUTPUT

Program tested for smaller sizes.

Explanation:

1. Two two dimensional integer arrays are declared.

2. The variable size is declared and initialized to 10.

3. The main() prompts the user to enter the elements for both arrays; 1 for white and 0 for black.

4. Both the arrays are initialized inside two for loops independently.

5. These arrays are passed as parameter to the method, recognition(), one at a time.

6. Inside recognition(), an integer variable, notImage is declared and initialized to 0. If any other integer, other than 0 or 1 is encountered in the respective arrays, this variable is initialized to -1.

7. Inside main(), an integer variable, err, is declared. This variable stores the value returned by recognition().

8. Depending on the value of variable, err, message is displayed to the user appropriately.

You might be interested in
Please name the OOP term that allows children classes to have methods with the same names as methods in their parents.
RSB [31]

Answer:

Inheritance

Explanation:

3 0
3 years ago
Alicia has filed a complaint regarding a serious hazard that could result in a fatality or serious injury. How will OSHA most li
Galina-37 [17]

osha will insist that the hazard be removed within x amount of time. if there is no compliance,the company will face a hefty fine and possible closure of a facility.

4 0
3 years ago
Read 2 more answers
Can you help me with this question please ​
Flura [38]
D. half period because it is the converting of bidirectional current flow to unidirectional currency flow.
3 0
3 years ago
What should a good interface delight incorporate?
antoniya [11.8K]

<u>Answer:</u>  

A) a very long but detailed menu system

<u>Explanation:</u>

A <em>detailed menu will never attract or support the user in any form</em>. It might be difficult to use the application for longer time due to the <em>un supportive menu format.</em>

Option B: This option might look closer to the answer but it might not attract if many users are unaware of the latest changes.

Option C: The application should support and should not challenge the user. It is not a quiz or game show to challenge people.

Option D: Any GUI should be attractive so that the user tend to use it frequently.

8 0
3 years ago
How to file an appeal for social security ​
Anuta_ua [19.1K]
You can fill out an appeal online or call them
4 0
3 years ago
Other questions:
  • When a chart is inserted into a Word document, it displays
    15·2 answers
  • Write a MIPS program to generate the following series of integers: 1, 2, 3. 6, 9, 18. 27, 54. 81. If you are curious where this
    13·1 answer
  • What is SAFFiR? (The robot)
    12·1 answer
  • Which of the following types does the Java programming language support?
    9·2 answers
  • Every UNIX and Linux system contains full documentation of UNIX commands in the _____ pages.
    9·1 answer
  • Refer to the exhibit. The web servers WS_1 and WS_2 need to be accessed by external and internal users. For security reasons, th
    12·1 answer
  • What is a foreign key and how does it provide referential integrity?
    10·1 answer
  • how does the use of data abstraction manage complexity in program code? how does using lists make a program easier to develop an
    5·1 answer
  • What is number system​
    15·1 answer
  • A program that organizes sequences of automated provisioning tasks. A. Application Packager B. Sequence Manager C. Sequence Logg
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!