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
Why does my Chromebook keep on turning my new tabs into clever tabs?
Alina [70]

Answer:

Ok, so it's not letting me submit a text response, so I'll attach an image of my answer.

Explanation:

6 0
2 years ago
Read 2 more answers
Write a program that ask a user to input radius of a circle and display circumference of a circle
uranmaximum [27]

Answer:

Explanation:

8

4 0
3 years ago
Which details apply to a financing contract? Check all that apply
Nina [5.8K]
Correct answer choices are:

Requires a credit check
Includes interest rate information
Requires a signature for rent-to-own agreements

Contract finance is that the name was given to a debt that's provided after signing a legal contract document that your business has won and also the cash should be accustomed to complete the contract work.
3 0
3 years ago
Read 2 more answers
Isabel and Jared work for the same company but in different departments. Their workstations are both part of the company's compu
Nina [5.8K]

Network access limitations implemented from their local IT Department

3 0
3 years ago
Read 2 more answers
Witch is the correct description of the first act in a classical game story structure
3241004551 [841]
Hitler because,Hitler was a great and wealthy companion
4 0
4 years ago
Other questions:
  • Simon wants to use an invoice template created by Office.com. The first step after selecting the File tab is to select
    14·1 answer
  • Which of these expressions is used to check whether num is equal to value?
    12·1 answer
  • What are the five resources paid for by local taxes
    15·1 answer
  • What is another term used for data dictionary?
    12·1 answer
  • A macro enables you to automate repetitive tasks by
    5·1 answer
  • Assume that month is an int variable whose value is 1 or 2 or 3 or 5 ... or 11 or 12. Write an expression whose value is "jan" o
    10·1 answer
  • Justify the need for branching and jump codes in the instruction set using real world scenarios
    6·1 answer
  • HELP! WILL GIVE BRAINLYEST!
    13·1 answer
  • Discuss the factors which cause imbalance in the environment.
    8·1 answer
  • What is an example of new technology having a negative impact on sustainability?.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!