Java BigInteger probablePrime() methodThe probablePrime() method of Java BigInteger class is used to find a probably prime number of any bit length. This method returns a positive BigInteger that is probably prime, with the specified bitLength. Syntax:Parameter:bitLength- bitLength of the returned BigInteger. rnd- source of random bits used to select candidates to be tested for primality. Returns:This method returns a BigInteger of bitLength bits that is probably prime. Exception:ArithmeticException- if bitLength < 2. Note: The probability that a BigInteger returned by this method is composite does not exceed 2-100.Example 1Test it NowOutput: ProbablePrime of bitlength 4 is 11 Example 2Test it NowOutput: Exception in thread "main" java.lang.ArithmeticException: bitLength < 2 at java.math.BigInteger.probablePrime(BigInteger.java:695) at BigIntegerProbablePrimeExample2.main(BigIntegerProbablePrimeExample2.java:13) Example 3Test it NowOutput: ProbablePrime of bitlength 10 is 857 Next TopicJava BigInteger |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India