Question: For this last prime number program, implement The Sieve of Eratosthenes to find the prime numbers between 2 and 1,000,000. Info on the Sieve can

For this last prime number program, implement The Sieve of Eratosthenes to find the prime numbers between 2 and 1,000,000. Info on the "Sieve" can be found here: Your program should be as similar as possible to previous primes labs developed and assigned in class to allow for "apples to apples" comparison between versions of program. At the end of your program, display the primes and the total number of primes. Place your solution in ~/PF2/lab3/Lab3.java

This is what I have so far:

public class Lab3 { public static boolean primes[];

public static boolean isPrime(int n) { return (primes[n]); }

public static void init(int n) {

int root = (int)Math.sqrt(n);

primes = new boolean[120];

for (int i = 0; i<=root; i++) { return true;

for (int j = 2; j<=primes.length; j++) { if (j = true) { return true; } else { continue; } } }

} public static void main (String args[]) { int c =0;

long start, end, mstime;

final int LIMIT = 120;

start = System.currentTimeMillis();

init(LIMIT);

for (int i = 2; i

if (isPrime(i)) { System.out.println(i); c++; } } end = System.currentTimeMillis();

mstime = end - start;

System.out.println("#primes = " + c + ", mstime = " + mstime); } }

I am only having problems with the "for" loops, help please.

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!