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
djverab [1.8K]
3 years ago
5

Write a Java program that creates a two-dimensional array of type integer of size x by y (x and y must be entered by the user).

The program must fill the array with random numbers from 1 to 100. The program must prompt the user to enter a search key between 1 and 100. Then, the program must check whether the search key is available in the array and print its location.
Computers and Technology
1 answer:
spayn [35]3 years ago
4 0

Answer:

The program in Java is as follows:

import java.util.*;

public class Main{

public static void main(String[] args) {

 Scanner input = new Scanner(System.in);

 int x, y;

 System.out.print("x and y: ");

 x = input.nextInt(); y = input.nextInt();

 int[][] twoD_arr = new int[x][y];

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

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

         twoD_arr[i][j] = (int)(Math.random() * 100);      }  }

 System.out.print("Search: ");

 int numSearch = input.nextInt();

 int count = 0;

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

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

         if(twoD_arr[i][j] == numSearch){

             count++;

             System.out.println("Row "+(1+i)+" Column "+(j+1));          }          }    }

 if(count == 0){ System.out.print("Key does not exist");  }

}

}

Explanation:

Declare x and y

 int x, y;

Prompt user for x and y

 System.out.print("x and y: ");

Get input for x and y

 x = input.nextInt(); y = input.nextInt();

Declare the two dimensional array

 int[][] twoD_arr = new int[x][y];

Iterate through the rows

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

Iterate through the columns

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

Get input for each cell

         twoD_arr[i][j] = (int)(Math.random() * 100);      }  }

Prompt the user for search key

 System.out.print("Search: ");

Get input search key

 int numSearch = input.nextInt();

Initialize count to 0

 int count = 0;

Iterate through the rows

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

Iterate through the columns

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

Check if current element and the search key are the same.

         if(twoD_arr[i][j] == numSearch){

Increment count by 1, if they are the same

             count++;

Print the position

             System.out.println("Row "+(1+i)+" Column "+(j+1));          }          }    }

If count is 0, print key does not exist

 if(count == 0){ System.out.print("Key does not exist");  }

You might be interested in
You are planning to use Spark to create a machine learning model that recommends restaurants to users based on user details and
SCORPION-xisa [38]

Answer:

The third point i.e " Use an alternating least squares (ALS) algorithm to create a collaborative filtering solution" is the correct answer .

Explanation:

The Alternating Less Squares  is the different approach that main objective to enhancing the loss function.The Alternating Less Squares process divided the matrix into the two factors for optimizing the loss .The divided of two factor matrix is known as item matrix or the user matrix.

  • As we have to build the machine learning model which proposes restaurants to restaurants that are based on the customer information and the prior restaurant reviews the alternating least squares is the best model to implement this .
  • All the other options are not the correct model also they are not related to given scenario that's why they are incorrect options.
4 0
3 years ago
what is the term used when a virus takes control of features on your computer and transports files or information automatically?
Akimi4 [234]

Answer: a "worm"

Explanation:

3 0
3 years ago
What if an input is always the same for an algorithm? <br> (Plz do not answer if you don’t know)
skelet666 [1.2K]
Given a particular input, will always produce the same output, with the underlying machine always passing through the same sequence of states.
5 0
3 years ago
When selecting font size in a document, ____ points equals one-inch-tall text?
IgorC [24]
Hello <span>Jhigg4685 
</span><span>

Answer: When selecting font size in a document, 72 points equals one-inch-tall text?


I hope this helps
-Chris</span>
3 0
4 years ago
A college asks you to write about a novel that is meaningful to you. What should you include in this essay?
Marina CMI [18]

The answer is C because they want you to compare it your or others lives.

4 0
3 years ago
Other questions:
  • An example of software is
    9·2 answers
  • Which of the following cannot be copyrighted?
    10·1 answer
  • The word biodegradable on a label doesn't necessarily mean a product is environmentally safe?
    12·1 answer
  • 2. Suppose a computer using direct mapped cache has 220 words of main memory and a cache of 32 blocks, where each cache block co
    10·1 answer
  • You work in an office that uses Linux servers and Windows servers. The network uses both the TCP/IP protocol. The Linux server i
    11·1 answer
  • What is a hash function? A. A function that computes the location of the values in the array B. A function has allocated memory
    7·2 answers
  • Julie: 3: 36, 6:72, 9:108....tell me the next 3 ratios * math*
    11·1 answer
  • Is there a way to delete a question on brainly?
    8·2 answers
  • A leading pharmaceutical company is launching a major transformation of its entire Cloud operations in order to more quickly and
    13·1 answer
  • Daily IT Question
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!