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 are my texts green when texting another iphone.
Ede4ka [16]

Answer:

The green message background indicates the traditional SMS text message. It actually means a message that you have sent to someone else is through SMS message service instead of Apple iMessage

:

4 0
2 years ago
For any element in keysList with a value smaller than 40, print the corresponding value in itemsList, followed by a comma (no sp
givi [52]

Answer:

u look se33y yessir

Explanation:

......................................

7 0
2 years ago
Help please not trying to fail
deff fn [24]

Answer:

B. Everywhere CFCI is not

8 0
3 years ago
Why is it important to know who reviews the information posted on a Web site?​
Aleks [24]

.bordered {    width: 200px;    height: 100px;    padding: 20px;    border-width: 6px;    border-color: pink;    border-style: dashed solid double;  }Why there is a need of concrete and coherent presentation ? ( class 9 ) {information technology}

5 0
3 years ago
Is megan the stallion hot
astraxan [27]

Answer:

Explanation:

Cool

8 0
2 years ago
Read 2 more answers
Other questions:
  • Format Painter cannot be used to copy only character attributes. True or False
    12·1 answer
  • What is the main purpose of broadcasting via satellite? A. To enable signal reception at night B. To convert analog signals to d
    5·1 answer
  • . It is essential for a relay energized by alternating current to have A. many turns of small wire. B. a laminated core and a sh
    8·1 answer
  • The ____________________ packet-filtering firewall allows only a particular packet with a particular source, destination, and po
    10·1 answer
  • Which of the following is a school-to-work program that provides the student with paid employment, school credit, and school gra
    7·2 answers
  • Can someone tell me a user to an admin on brainly I got a person sending "inappropriate pictures" all over brainly
    13·1 answer
  • A palindrome is a string that reads the same both forward and backward. For example, the string madam is a palindrome. Write a p
    13·1 answer
  • When working on developing an ability, it is important to get feedback to know how you are doing.
    6·1 answer
  • How network diagram help in scheduling a project? Draw activity network diagram as per given
    7·1 answer
  • Icon view, list view, and details view are all common views provided by which kind of program?
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!