Java BigInteger nextProbablePrime() Method

The nextProbablePrime() method of Java BigInteger class is used to find the next Prime Number greater than the current BigInteger. This method returns the first integer greater than this BigInteger that is probably prime.

Syntax:

Parameter:

NA

Returns:

This method returns the first integer greater than this BigInteger that is probably prime.

Exception:

ArithmeticException < this < 0 or this is too large.

Note:
  • This method will never skip over a prime when searching. If it returns p, there is no prime q such that this < q < p.
  • The probability that the number returned by this method is composite does not exceed 2-100.

Example 1

Test it Now

Output:

Next Probable Prime after 10 is 11
Next Probable Prime after 23 is 29

Example 2

Test it Now

Output:

java.lang.ArithmeticException: start < 0: -23

Next TopicJava BigInteger




Latest Courses