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.
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.
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.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images