cynosurex.math
Class Prime

java.lang.Object
  extended by cynosurex.math.Prime

public class Prime
extends java.lang.Object

The approach of this class works for relatively small (32-bit) prime numbers. Use BigInteger class to generate large primes (typically hundreds or thousands of digits), with some degree of certainty. A prime number is an integer greater than 1, with only itself and 1 as divisors. The first few primes are 2, 3, 5, 7, 11, and 13.


Constructor Summary
Prime()
           
 
Method Summary
static int getNext(int n)
          This method finds the next smallest prime that is greater than or equal to n.
static boolean isPrime(int n)
          This method determines whether the specified number is a prime number.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Prime

public Prime()
Method Detail

isPrime

public static boolean isPrime(int n)
This method determines whether the specified number is a prime number. The method handles the special case of 2 (which is prime). It then screens out other positive even numbers (which are not prime, because they have 2 as a divisor). The isPrime method then tries odd divisors starting at 3 and going up to the square root of the number.

Parameters:
n - The number to test.

getNext

public static int getNext(int n)
This method finds the next smallest prime that is greater than or equal to n.