Question: A program that generates random numbers that are between 1 and 100, then searches for the values. /**************************************************************************************************************************** Declare an array list to hold random

A program that generates random numbers that are between 1 and 100, then searches for the values.

/****************************************************************************************************************************

Declare an array list to hold random numbers. ? Get input for how many random numbers to use. ? Using a for loop, add random numbers to the array list between 1 and 100. ? Get input for value to be searched. ? Using a for-each loop and a sequential search, search through the array list for the search term entered. 90% o Output Unsorted list and: o For each match found, output # found at location: # (see example) ? Use java collections to sort the array list. ? Using a for-each loop and a sequential search, search through the array list for the search term entered. o Output Sorted list and: o For each match found, output # found at location: # (see example) ? Only print the headers and values if the search item is found. Print the total value of all random numbers added together after the search has complete.

***********************************************************************************************************************/

Output sample

A program that generates random numbers that are between 1 and 100,

then searches for the values. /**************************************************************************************************************************** Declare an array list to hold

/******************************************************************************************

The code I came up with is below but is majorly flawed am sure that it is not right and running into plenty errors along the way.

import java.util.Scanner; import java.util.Random; import java.util.ArrayList;

public class ArrayListWork { public static void main(String[] args) { Scanner scan = new Scanner(System.in); Random rand = new Random(); ArrayList array1 = new ArrayList(); // Array to contain unsorted list int ele1,temp,sum = 0; // value holders int search; // search value input System.out.print("How many random numbers between 1 and 100? "); // asking how many random numbers search = scan.nextInt(); for (int i = 0;i How many random numbers between 1 and 100 1000 Which random number are you searching for? 5 Unsorted List 5 found at location 502 5 found at location 725 5 found at location: 856 5 und at location 924 Sorted List 5 found at location 40 5 found at location 41 found at location 42 5 5 found at location 43 Total of all numbers 49089

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!