nextProbablePrime(): This method is available in java.math.BigInteger class of Java.
Syntax:
BigInteger java.math.BigInteger.nextProbablePrime()
This method returns the first integer greater than this BigInteger that is probably prime. The probability that the number returned by this method is composite does not exceed 2^(-100) or (2 power -100).
Note If it returns p, there is no prime q such that this < q < p.
Returns: the first integer greater than this BigInteger that is probably prime.
Throws: ArithmeticException - this < 0 or this is too large.
For Example:
BigInteger bigInteger = new BigInteger("1234")
bigInteger.nextProbablePrime() = > It returns 1237.
Approach
Java
import java.math.BigInteger;public class BigIntegernextProbablePrime {public static void main(String[] args) {BigInteger bigInteger = new BigInteger("1234");System.out.println(bigInteger.nextProbablePrime());}}
Output:
1237
No comments:
Post a Comment