Question: Write a program that will generate 5 random integers between 1 and 10 and store them in an ArrayList (see 2.10 if you don't remember
Write a program that will generate 5 random integers between 1 and 10 and store them in an ArrayList (see 2.10 if you don't remember how to generate random integers). Ask the user for an integer to search for in the list, then output the index position of that integer or state that their integer is not in the list. Finally, sort the list, then output the contents of the sorted list. You will use two static methods:
- public static int search(ArrayList
list, int num) - searches the list for the user's integer and returns the index position of where it is found, or -1 if it is not found
- use sequential (linear) search starting at the END of the array and moving toward the beginning
- if the user's integer appears more than once, return the larger index
- public static void sort(ArrayList
list) - uses Selection Sort starting at the END of the list and moving toward the beginning
Example output:
Enter an integer: 3
3 is at index position 4
The sorted list is: [2, 3, 5, 8, 9]
Enter an integer: 3
3 is not in the list
The sorted list is: [2, 4, 5, 7, 10]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
