Check if a BigInteger is a probable prime number in Java
Description
The following code shows how to check if a BigInteger is a probable prime number.
Example
//from w w w. ja v a2s. com
import java.math.BigInteger;
public class Main {
public static void main(String args[]) {
BigInteger n = new BigInteger("1000000000000");
BigInteger one = new BigInteger("1");
while (!n.isProbablePrime(7))
n = n.add(one);
System.out.println(n.toString(10) + " is probably prime.");
System.out.println("It is " + n.bitLength() + " bits in length.");
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »