Java Data Type Tutorial - Java BigInteger .isProbablePrime (int certainty)








Syntax

BigInteger.isProbablePrime(int certainty) has the following syntax.

public boolean isProbablePrime(int certainty)

Example

In the following code shows how to use BigInteger.isProbablePrime(int certainty) method.

//www  . j  a v a 2  s. c  o m

import java.math.BigInteger;

public class Main {

  public static void main(String[] args) {

    // assign values to bi1, bi2
    BigInteger bi1 = new BigInteger("7");
    BigInteger bi2 = new BigInteger("9");

    // perform isProbablePrime on bi1, bi2
    Boolean b1 = bi1.isProbablePrime(1);
    Boolean b2 = bi2.isProbablePrime(1);
    Boolean b3 = bi2.isProbablePrime(-1);

    System.out.println(b1);
    System.out.println(b2);
    System.out.println(b3);
  }
}

The code above generates the following result.