How to run isProbablePrime method in Java

In this tutorial, we have to check whether the given number is prime or not using the Java BigInteger class isProbablePrime method.

A Prime number is a natural number greater than 1 and whose only positive divisors are 1 and the number itself. Example: 2,3,5,7,11,13...etc.

Here, isProbablePrime returns true if BigInteger is probable prime. false if it's definitely composite. If certainty is <=0, true is returned.

 

package isProbableprime;
import java.util.*;
public class isprobableprime 
{
  private static final Scanner scanner = new Scanner(System.in);
  public static void main(String[] args) 
  {
        java.math.BigInteger n = scanner.nextBigInteger();
        Boolean a=n.isProbablePrime(1);
        if(a==true)
        {
            System.out.println("prime");

        }
        else
        {
            System.out.println("not prime");

        }
        

        scanner.close();
    }
}

 

 

Output:-

 

output

 

Output2

Project Files

Loading...
..
This directory is empty.

Comments (0)

Leave a Comment