Sunday, 8 May 2016

How to generate next prime number of any number using Java API ?


Use Java.math.BigInteger.nextProbablePrime()

Example
BigInteger num = BigInteger.valueOf(number);
BigInteger nextPrimeNum = num.nextProbablePrime();
System.out.println("Next prime number : " + nextPrimeNum);

No comments:

Post a Comment

Note: only a member of this blog may post a comment.