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
77julia77 [94]
3 years ago
12

Write a java program to create an array of 5 numbers. accept a number and search for that number in the array using linear searc

h. Display the appropriate message
Computers and Technology
1 answer:
yKpoI14uk [10]3 years ago
5 0

Answer:

import java.util.Random;

public class brainly {

   public static void main(String[] args) {

       int[] test_list = create_array(5);

       int target = 2; // change all of these

       int index = search(test_list, target);

       if (index == -1) {

           System.out.println("Target " + target + " not found.");

       }

       else {

           System.out.println("Target " + target + " found at index " + index);

       }

   }

   public static int[] create_array(int num) {

       Random rand = new Random();

       int[] list = new int[num];

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

           int rand_int = rand.nextInt(num); // change this to what you want

           list[i] = rand_int;

           System.out.print(rand_int);

       }

       System.out.println("\n");

       return list;

   }

 

   public static int search(int arr[], int x) {  

       int n = arr.length;  

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

           if(arr[i] == x)  

               return i;  

       }  

       return -1;  

   }  

}

Explanation:

First off, your question is very vague, anyway, here is my interpretation.

The method create_array creates an array with the specified length.

It creates an array out of random numbers from 0 to the length.

The method search method is a simple linear search, stepping by one each cycle.

I honestly have no idea what the question is, but I added an attachment of the code.

Download java
You might be interested in
Calvin is creating a 3D shell of a turtle. He is creating a sculpted, intricate design for the pattern he wants on the shell, bu
PSYCHO15rus [73]
A is right I did this
7 0
2 years ago
What are the three different categories of the types of rule ?
slamgirl [31]
Depends on what rules your talking about
3 0
3 years ago
How can a Word user insert a page break into a document to isolate a table on a new page?
ki77a [65]

Answer: hit control key and enter key at the same time.

Explanation:

on the keyboard hold down the control key and enter key.

6 0
3 years ago
Read 2 more answers
Which characteristics describe the WMV video file format? Choose all that apply.
Lelechka [254]

Answer:

the answer is A, B, C hope this helps.

8 0
2 years ago
Some designer suggest that speech recognition should be used in tale phone menu system. This will allow users to interact with t
Sergio [31]

Answer:

My two arguments against the proposal are based on physical side effects and background noise interference.

Explanation:

To start with physical side effects, the use of speech recognition technology might make users experience physical discomfort. This is due to the fact that users who interact with the system by speaking for a long period would experience dry mouth, temporary loss of voice, vocal problems and muscle fatigue. In addition, the fact that users would always speak in an unnatural way to make the system interpret commands effectively could lead to voice strain.  

Also, users need to be in a quiet environment before they can get the best out of speech recognition technology. This is because background noise can interfere with commands and create a mix-up which the system cannot interpret. In other words, when an environment is noisy, speech recognition technology would find it difficult to differentiate between users voice and background noise.

4 0
3 years ago
Other questions:
  • Kendra needs to configure a visual alert for an appointment that she is creating for next week. What should she configure?
    11·1 answer
  • Design a class named QuadraticEquation for a quadratic equation ax^2+bx+x=0. The class contains: **private data fields a, b, and
    11·1 answer
  • A serialized object is ________. an object represented as a sequence of bytes used to store the object's data in a file an objec
    5·2 answers
  • When you are given a set of tables and asked to create a database to store their data, the first step is to ________?
    8·1 answer
  • Five features of any window​
    14·1 answer
  • Small data files that are deposited on a user's hard disk when they visit a website are called _______.
    6·2 answers
  • Both UDP and TCP use port numbers to identify the destination entity when delivering a message. Give at least one reason for why
    12·1 answer
  • Need help on Assignment 4: Evens and Odds
    5·1 answer
  • What is the output by the code system.out.print(8-4+2);
    13·1 answer
  • Website designers work on the code and programming of a website, not the style or layout of the site.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!