The Sieve of Eratosthenes is a method of finding prime numbers. Write a Java program which implements
Fantastic news! We've Found the answer you've been seeking!
Question:
The Sieve of Eratosthenes is a method of finding prime numbers.
Write a Java program which implements described algorithm for an array of 1000 elements. Your class MUST have the following methods:
-
public static void main(String[] args)
- creates array of integersint[] a
and calls methodsinit(a)
,findPrimes(a)
andprintPrimes(a)
-
public static void init(int[] a)
- takes a reference to array of integers and initializes all elements to 1, except elements at 0 and 1 -
public static void findPrimes(int[] a)
- implements the algorithm of Eratosthenes -
public static void printPrimes(int[] a)
- prints prime numbers in the range 2 to 999.
Related Book For
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates
Posted Date: