Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started