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
How can you troubleshoot Internet access problems?
joja [24]

Answer:

Check the network icon (or wireless connection settings) to see if you have Internet access. ...

Check for changes to proxy settings.

Check the network cables if your computer is wired to the router.

Reset your router.

Check your firewall or security software.

Hopefully this helps.

8 0
3 years ago
Algorithm that has been coded into something that can be run by a machine.
hram777 [196]
The answer is program
8 0
3 years ago
Why is there no window on dishwsher
olchik [2.2K]

Because most people really don't want or need to see what's in there.

If you want to, open the door during the cycle. It won't harm anything.

If you're curious to see a dishwasher in action, some appliance showrooms have a display model, where the spray parts and the racks are in an entirely transparent box. They're to show how powerfully and completely the stuff inside will get cleaned, but you can also see how the dishwasher is intended to work, by filling with just a couple of inches of water, and then recirculating it for the duration of the cycle, to loosen the stuff on the dishes.

3 0
3 years ago
Read 2 more answers
If you want to present slides to fellow students or co-workers,which productivity software should you use to create them?
Tamiku [17]
Just use prezi.com hope that helps.
6 0
4 years ago
Read 2 more answers
Use the drop-down menus to match each description to the correct term.
maw [93]

Answer:

unknown

Explanation:

the location of each drop-down menu is not given and the answer choices are not shown as well, if they are it is hard to see, try reposting the question with maybe a bracket set ' [ ] ' to represent the blanks, then below you can number the answers available, such as this

President [ ] was in office during the civil war, after the [ ] won the war, he united the states once again

1st BLANK

Abraham Lincoln

John Adams

George Bush

2nd BLANK

Union

Confederates

British

(i just made up this question, its not any part of any test questions)

i hope this helps you out a lil bit :)

4 0
3 years ago
Read 2 more answers
Other questions:
  • Thomas asked his friend for a software suite. His friend had the software suite in his computer and he copied it into a small, r
    11·1 answer
  • What is a independent variable
    11·1 answer
  • What features are provided by most GUIs?
    7·1 answer
  • The term "Cloud" refers to what option(s) below? (Select all that apply)
    13·1 answer
  • you are the manager of a virtual team that is working on a project. You uploaded a Word document to an OneDrive account that you
    9·1 answer
  • Two routers connect with a serial link, each using its S0/0/0 interface. The link is currently working using PPP. The network en
    6·1 answer
  • Assuming the Direct Hashing function and the Subtraction preprocessing algorithm is used to map keys into indices, give the inde
    15·1 answer
  • Which composer below was not part of the classical period? <br> A. Beethoven B. Bach<br> C. Mozart
    6·1 answer
  • To provide for unobtrusive validation, you can install the ____________________ package for unobtrusive validation.
    11·1 answer
  • The term ________ refers to the use of a single unifying device that handles media, Internet, entertainment, and phone needs. Gr
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!