Question: 16.1 Prime numbers revisited Look up the algorithm to calculate primes using a sieve of Eratosthenes. Implement an application which calculates ever-increasing prime numbers, only

16.1 Prime numbers revisited Look up the algorithm to calculate primes using a sieve of Eratosthenes. Implement an application which calculates ever-increasing prime numbers, only stopping when you forcefully quit the application. Store all numbers in an ArrayList. Hint: this one seems simpler than it actually is. First design the algorithm. 16.2 Using Sets Write the following (small) application. The application has an object of the class HashSet, in which it can only store objects of type Integer. The application then generates a few thousand integers between 0 and 100, wraps them in an Integer, and stores them in the HashSet. After that, it prints the content of the Set. What do you see? Change the HashSet to a SortedSet. What changes in the output? Write a Comparator for sorting Integer. It uses the following rules: odd numbers are always larger than even numbers, and if they are both odd (or both even), the regular order counts. Use this Comparator in the SortedSet. What changes in the output? Instead of a SortedSet, use a PriorityQueue. After storing the random integers, you now need to retrieve them using another loop. Repeat the previous paragraphs with this kind of Collection and watch the difference
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
