public class PrimeNumberFunctions
extends java.lang.Object
Constructor and Description |
---|
PrimeNumberFunctions() |
Modifier and Type | Method and Description |
---|---|
static int[] |
allPrimesFromTo(int lowerBound,
int upperBound)
Returns all prime numbers between (and including) lowerBound and upperBound.
|
static int[] |
allPrimesTo(int upperBound)
Wrapper for allPrimesFromTo(0, upperBound).
|
static int[] |
firstPrimes(int amount)
Returns a list containing the first X primes.
|
static int |
generateAnotherPrime(int lowerBound,
int upperBound,
int lastPrime,
int maxTries)
Returns a prime number different from lastPrime between lowerBound and upperBound.
|
static int |
generatePrime(int lowerBound,
int upperBound)
Generates a random prime number between lowerBound and upperBound.
|
static boolean |
isPrime(int number)
Returns whether a number is prime or not.
|
static boolean |
isPrime(long number)
Returns whether a number is prime or not.
|
static boolean |
isSuperPrime(int number)
Returns whether the specified number is a super prime number.
|
static int |
nextPrime(int number)
Returns the next prime on the number line after any given number.
|
static int[] |
sieveOfEratosthenes(int upperBound)
Returns an array containing all prime numbers from 2 to upperBound.
|
public static int nextPrime(int number)
number
- any number.public static boolean isPrime(int number)
number
- any number.public static boolean isPrime(long number)
number
- any number.public static boolean isSuperPrime(int number)
number
- any number.public static int[] allPrimesTo(int upperBound)
upperBound
- the upper bound to search for primes up to.public static int[] allPrimesFromTo(int lowerBound, int upperBound)
lowerBound
- the lower bound to search for primes from.upperBound
- the upper bound to search for primes up to.public static int[] firstPrimes(int amount)
amount
- the desired amount of primespublic static int generatePrime(int lowerBound, int upperBound)
lowerBound
- the lower bound to search for primes from.upperBound
- the upper bound to search for primes up to.public static int generateAnotherPrime(int lowerBound, int upperBound, int lastPrime, int maxTries) throws NoMorePrimesFoundException
lowerBound
- the lower bound to search for primes from.upperBound
- the upper bound to search for primes up to.lastPrime
- any prime within lowerBound and upperBound.maxTries
- the maximum amount of tries to generate a different prime number.NoMorePrimesFoundException
- if no different prime than lastPrime is found between lowerBound and
upperBound within maxTries tries.public static int[] sieveOfEratosthenes(int upperBound)
upperBound
- any upper Bound. Must be greater than 1.