Question: JAVA PROGRAM (Please screenshot your output) The Greek mathematician Eratosthenes (276 BCE 195 BCE) devised a method of finding prime numbers, as follows: Create a

JAVA PROGRAM (Please screenshot your output) The Greek mathematician Eratosthenes (276 BCE 195 BCE) devised a method of finding prime numbers, as follows:

  • Create a list of consecutive integers from 2 up to the desired limit.
  • Beginning with 2, mark off every second integer on the list.
  • Move to the next unmarked number (which will be 3) and mark off every third integer.
  • Move to the next unmarked number (which will be 5) and mark off every fifth integer.
  • Move to the next unmarked number (which will be 7) and mark off every seventh integer.
  • Move to the next unmarked number (which will be 11) and mark off every eleventh int
  • Continue until the end of the list has been reached.

When completed, every unmarked entry in the list (beginning with 2) represents a prime number.

Implement the Sieve of Eratosthenes with a program which performs the following tasks:

  • Display a friendly greeting to the user.
  • Prompt the user for a start value > 1. We will use this later.
  • Prompt the user for a stop value. This will be the size of the array 1.
  • Use the stop value to create an array of type boolean and set every value to true.
  • Execute the Sieve of Eratosthenes algorithm (using false to mark off entries)
  • Display the total number of primes found in the interval [start, stop].

What is the largest array size you can run using Java? If your program can handle arrays of larger than 2 GB, make sure you input the users integer as a long, not an int. If not, explain why.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!