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
What is number system?<br>​
MrMuchimi

Answer:

A numeral system is a writing system for expressing numbers; that is, a mathematical notation for representing numbers of a given set, using digits or other symbols in a consistent manner. The same sequence of symbols may represent different numbers in different numeral systems.

Explanation:

8 0
2 years ago
In this lab, you complete a C++ program that swaps values stored in three int variables and determines maximum and minimum value
Sergio039 [100]

Answer:

Following are the code to the given question:

#include <iostream>//header file

using namespace std;

int main()//main method

{

int first = 0,second = 0,third = 0;//defining integer variable  

int temp; //defining integer variable

const string SENTINEL = "done"; // defining a string variable as constant  

string repeat;// defining a string variable  

bool notDone = true; //defining bool variable

cout << "Enter first number: ";//print message

cin >> first;//input value

cout << "Enter second number: ";//print message

cin >> second;//input value

cout << "Enter third number: ";//print message

cin >> third;//input value

while(notDone == true)//defining a loop to check the value  

{

if(first > second)//use if to compare first and second value

{

int temp = first;//defining temp to hold first value

first = second;//holding second value in first variable

second = temp;//holding temp value in second variable

}

if(second > third)//use if to compare second and third value

{

int temp = second;//defining temp to hold second value

second = third;//holding second value in third variable

third = temp;//holding temp value in third variable

}

cout << "Smallest: " << first << endl;//print smallest value

cout << "Next smallest: " << second << endl;//print Next smallest value

cout << "Largest: " << third << endl;////print Largest value

cout << "Enter any letter to continue or done to quit: ";//print message

cin >> repeat;//holding string value

if (repeat == SENTINEL)

{

notDone = false;//holding bool value

}  

else //else block

{

cout << "Enter first number: ";//print message

cin >> first;//input value

cout << "Enter second number: ";//print message

cin >> second;//input value

cout << "Enter third number: ";//print message

cin >> third;//input value

}

return 0;

}

}

Output:

Please find the attached file.

Explanation:

  • Inside the main method Four integer variable "first, second, third, and temp" is declared in which first three variable is used for input value and temp is used to compare value.
  • In thew next step, two string variable "SENTINEL and repeat" is declared in which "SENTINEL" is constant and a bool variable "notDone" is declared.
  • After input the value from the user-end a loop is declared that compare and swap value and print its value.

6 0
2 years ago
Which of the following is not a characteristic of Web 2.0?
Dmitry [639]

Answer:

c. mentorship programs taking place via the internet

Explanation:

The World Wide Web (WWW) was created by Tim Berners-Lee in 1990, which eventually gave rise to the development of Web 2.0 in 1999.

Web 2.0 can be defined as a collection of internet software programs or applications which avails the end users the ability or opportunity to share files and resources, as well as enhance collaboration over the internet.

Basically, it's an evolution from a static worldwide web to a dynamic web that enhanced social media. Some of the examples of social media platforms (web 2.0) are You-Tube, Flickr, Go-ogle maps, Go-ogle docs, Face-book, Twit-ter, Insta-gram etc.

Some of the main characteristics of Web 2.0 are;

I. Social networking.

II. Blogging.

III. Interactive comments being available on many websites.

Also, most software applications developed for Web 2.0 avails its users the ability to synchronize with handheld or mobile devices such as smartphones.

However, mentorship programs taking place via the internet is not a characteristic of Web 2.0 but that of Web 3.0 (e-mentoring).

7 0
2 years ago
Which set of symbols can be used to determine which calculations to perform first?
Monica [59]

Answer:

parentheses

Explanation: hope i helped <3 °ω°

5 0
3 years ago
Read 2 more answers
Identify a syntax used to create a spinner control using an input element. a. b. c. d.
Lorico [155]

Answer:

Option A:

<input name="name" id="id" type="number" value="value" step="value" min="value" max="value" />

Explanation:

Spinner control is a graphical control element where user can adjust the value by pressing up or down arrow button. An example is given in the attached image.

In HTML, one of the key attributes we must use to create a spinner control is "step". The attribute "step" is required to specify the interval of the step value when user press the up or down arrow button.

If we set the attribute values as follows:

  • type = "number"
  • value = 2
  • min = 0
  • max = 10

The setting above will give a spinner control with a range of legal numbers between 0, 2, 4, 6, 8 and 10.

6 0
3 years ago
Other questions:
  • What Is the output of the following: =OR (5 &lt;7, 16*Rand ()&gt;23,FALSE)
    5·1 answer
  • What so the term used to describe how many bits are used in each pixel?
    7·1 answer
  • How do i build a supercomputer.?
    11·1 answer
  • Write a routine to interchange the mth and nth elements of a singly-linked list. You may assume that the ranks m and n are passe
    10·1 answer
  • Look at the following program and answer the question that follows it. 1 // This program displays my gross wages. 2 // I worked
    8·1 answer
  • You have a large TCP/IP network and want to keep a host's real time clock synchronized. What protocol should you use?
    10·1 answer
  • A strategic information system can be any kind of information system that uses information technology to help an organization __
    11·1 answer
  • What should you include in a persuasive speech
    14·1 answer
  • How do u type faster
    5·1 answer
  • Omo help me i need it now.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!