Sunday, 8 May 2016

How to check if a number is prime (primality) using Java API ?


Use Java.math.BigInteger.isProbablePrime() which uses Miller–Rabin primality Algo.

Example
BigInteger num = BigInteger.valueOf(number);
System.out.println("is Prime number ? " + num.isProbablePrime());

No comments:

Post a Comment

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