The java.math.BigInteger.isProbablePrime(int certainty) method is used to tell if this BigInteger is probably prime or if it’s definitely composite. This method checks for prime or composite upon the current BigInteger by which this method is called and returns a boolean value. It returns true if this BigInteger is probably prime, false if it’s definitely composite. If certainty is <= 0, true is returned.
public boolean isProbablePrime(int certainty)
Parameters: This method accepts a mandatory parameter certainty which is a measure of the uncertainty that is acceptable to the user. This is due to the fact the BigInteger is a very very large number and finding exactly if it is prime is very difficult and expensive. Hence it can be said that this method checks for the prime of this BigInteger based on a threshold value (1 – 1/2certainty).
Return Value: This method returns a boolean value stating whether this BigInteger is prime or not. It returns true if this BigInteger is probably prime, false if it’s definitely composite.
Below program is used to illustrate the isProbablePrime() method of BigInteger.
95848961698036841689418631330196 with certainty 1 false 95848961698036841689418631330196 with certainty 0 true 95848961698036841689418631330196 with certainty -1 true
654561561356879113561 with certainty 1 false 654561561356879113561 with certainty 0 true 654561561356879113561 with certainty -1 true
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- BigInteger gcd() Method in Java with Examples
- BigInteger add() Method in Java with Examples
- BigInteger nextProbablePrime() Method in Java with Examples
- BigInteger sqrtAndRemainder() Method in Java with Examples
- BigInteger intValueExact() Method in Java with Examples
- Java 8 | BigInteger shortValueExact() Method with Examples
- BigInteger subtract() Method in Java with Examples
- Java 8 | BigInteger longValueExact() Method with Examples
- Java 8 | BigInteger divideAndRemainder() method with Examples
- BigInteger multiply() Method in Java with Examples
- BigInteger divide() Method in Java with Examples
- Java 8 | BigInteger byteValueExact() method with Examples
- BigInteger and() Method in Java
- BigInteger pow() Method in Java
- BigInteger mod() Method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.