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
Based on the code you created in this Unit, propose a way to re-use most of the code (with different information in the variable
lisov135 [29]

Answer:

Is this a question or an answer

7 0
3 years ago
Everyone’s favorite speedy blue hedgehog recently returned to his 2D origins in a critically acclaimed side-scrolling game. What
forsale [732]
It was called sonic mania
3 0
4 years ago
Read 2 more answers
Project Description The Department plans to purchase a humanoid robot. The Chairman would like us to write a program to show a g
artcher [175]

Answer:

C++ code is explained below

Explanation:

#include <iostream>

#include <iomanip>

using namespace std;

int main()

{

// Variables to store inputs

string robot_name = "Nao";

string visitor_name;

int age, first_num, second_num;

// Constant variable initialisation for programmer name

const string programmer_name = "XXXXXXXX";

// Constant variable initialisation for assignment number

const string assignment_num = "123546";

// Constant variable initialisation for due date

const string due_date = "16 August, 2019";

// Displaying robot's name as script

cout << "Hello, welcome to Montgornery College!";

cout << "My name is " << robot_name << " . May I have your name?" << "\n\n";

// Taking visitor's name as input from the visitor

cin >> visitor_name;

// Displaying vistor's name as script

cout << "\n\nNice to have your with us today, " << visitor_name << "! ";

cout << "Let me impress you with a small game.";

cout << "Give me the age of an important person or a pet to you. ";

cout << "Please give me only a number!" << "\n\n";

// Taking human age as input from the visitor

cin >> age;

// Displaying human's age as script

cout << "\n\nYou have entered " << age << ". If this is for a person,";

cout << " the age can be expressed as " << age << " years or ";

// Computing months, days, hours, minutes and seconds from age input

double months = age*12;

double days = months*30;

double hours = days*24;

double minutes = hours*60;

double seconds = minutes*60;

// Computing dogs and fish age from human's age

double dogs_age = 7*age;

double gold_fish_age = 5*age;

// Displaying months, hours, minutes, hours and seconds as script

cout << months << " months or about " << days << " days or";

cout << " about " << fixed << setprecision(0) << hours << " hours or about " << minutes;

cout << " or about " << fixed << setprecision(0) << seconds << " seconds. If this is for a dog.";

// Displaying dogs age and gold fish age as script

cout << " it is " << dogs_age << " years old in human age.";

cout << " If this is for a gold fish, it is " << gold_fish_age;

cout << " years old in human age" << "\n\n";

cout << "Let's play another game, " << visitor_name << "!";

cout << "Give me a whole number." << "\n\n";

// Taking first whole number from the visitor

cin >> first_num;

cout << "\nVery well. Give me another whole number." << "\n\n";

// Taking second whole number from the vistor

cin >> second_num;

// Computing sum and division for displaying in the script

double sum = first_num+second_num;

double division = first_num/second_num;

float floatDivision = (float)first_num/second_num;

// Displaying sum and division script

cout << "\nUsing the operator '+' in C++,";

cout << " the result of " << first_num << " + " << second_num;

cout << " is " << sum << ". Using the operator '/', the result ";

cout << "of " << first_num << " / " << second_num << " is " << division;

cout << "; however, the result of " << first_num << ".0 /" << second_num;

cout << ".0 is about " << floatDivision << "." << "\n\n";

cout << "Do you like the games, " << visitor_name << "?";

cout << " If you do, you can learn more by taking our classes.";

cout << ". If you don't, I am sad, You should talk to our Chairman!" << "\n\n";

// Displaying Programmer Name, Assignment Number and due date to output screen

cout << "Programmer Name : " << programmer_name << endl;

cout << "Assignment Number : " << assignment_num << endl;

cout << "Due Date : " << due_date << endl;

 

return 0;

}

4 0
4 years ago
I will give the brainly or whatever its called
igomit [66]

Answer:

Just answer everyones questions and youll be at the right rank in no time

Explanation:

5 0
3 years ago
Read 2 more answers
Which is true about SSH and Telnet?
MaRussiya [10]

Answer:

Data is encrypted on SSH

Explanation:

Telnet and SSH both are the networking protocols. These protocol are used for the security of data. In telnet data is sent over the link without any encryption. That is the reason, in telnet protocol data is less secure.

In SSH (Security Shell) protocol data has been encrypted before transmission. The encryption of data make it more secure between transmitter and receiver.

So the true statement is that, SSH has data encryption.

8 0
3 years ago
Other questions:
  • List of most popular entertainment and culture websites
    15·1 answer
  • How do you make your graphics ADA accessible in BlueGriffon?
    12·2 answers
  • Spoken word and written word are different because what
    9·1 answer
  • Which of the following is NOT a useful strategy when making an informed purchase ?
    7·1 answer
  • Does white space have visual weight? Yes or No
    7·2 answers
  • When writing code, how can printing be useful?
    15·1 answer
  • PLEASE HELP!
    14·2 answers
  • _________ can be used to provide access control, confidentiality, data origin authentication, connectionless integrity, rejectio
    12·1 answer
  • How can you stretch or skew an object in paint
    13·1 answer
  • Which of the following protocols is used by an email client to retrieve messages from an email server, giving users the option t
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!