Sieve Of Eratosthenes

Download

Download jar file or use maven. psjava requires Java 1.6 (or above)

<dependency>
    <groupId>org.psjava</groupId>
    <artifactId>psjava</artifactId>
    <version>0.1.19</version>
</dependency>

Example Code

// Select sieve algorithm, and just call it.

PrimeNumberSieve sieve = SieveOfEratosthenes.getInstance();
Array<Integer> primes = sieve.calcList(30);

int number = primes.size(); // there are 10 primes. between [1~30]
int prime1st = primes.get(0); // first prime is 2
int prime8th = primes.get(7); // 8th prime is 19

Implementation


Copyright 2014 psjava team. View on GitHub