Question: Please only answer Exercise 3 i already have 1 and 2 Exercise 1: Write a program that generates a sequence of 20 random values between
Please only answer Exercise 3 i already have 1 and 2
Exercise 1:
Write a program that generates a sequence of 20 random values between 0 and 99 in an array, prints the sequence, sorts it, and prints the sorted sequence. Use the sort method from the standard Java library. You should use the Random class to generate your numbers. Don't just make them up. Also, please use Integer not Double for your numbers.
Hint:
Random ran = new Random(); int x = ran.nextInt(100);
or less concisesly:
int x = (int)(Math.random() * 100);
Exercise 2:
Write a program that stores a list of countries: "Egypt", "Switzerland", "Argentina", "Spain", "Portugal", "Luxemburg", etc.
Initialize your array with a single statement. Then print out the array.
Use the sort function as before to sort the countries in alphabetical order.
Reprint your array.
Exercise 3:
Implement exercises 1 and 2 using ArrayList.
Use the Collections.sort method for sorting. After you have printed and sorted your results, then append an additional element to each list and reprint your ArrayLists. Notice that the new items will appear just at the end and will not be sorted. Resort and print out the new ArrayLists again.
To clarify, you should print out your ArrayLists after your first sort, after adding items with the unsorted item, then after sorting again.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
