Java BigInteger isProbablePrime() Method

The isProbablePrime() method of Java BigInteger class is used to determine if the given number is prime or not. For certainty =1, this method returns true if this BigInteger is prime and false if this BigInteger is composite.

Syntax:

Parameter:

certainty - A measure of the uncertainty that the caller is willing to tolerate: if the call returns true the probability that this BigInteger is prime exceeds (1 - 1/2certainty). The execution time of this method is proportional to the value of this parameter.

Returns:

This method returns true if this BigInteger is probably prime, false if it's definitely composite.

Exception:

NA

Note: If certainty is ≤ 0, this method returns true.

Example 1

Test it Now

Output:

5 is prime with certainty 1 is true
5 is prime with certainty 0 is true
5 is prime with certainty -1 is true 

Example 2

Test it Now

Output:

8 is prime with certainty 1 is false
8 is prime with certainty 0 is true
8 is prime with certainty -1 is true

Example 3

Test it Now

Output:

9 is prime with certainty 1 is false
9 is prime with certainty 0 is true
9 is prime with certainty -1 is true

Next TopicJava BigInteger




Latest Courses