title: Check prime number for large values in java without using built-in functions.
body: <p><strong>I want to write a java program to check prime number for large values.</strong> I had written this code, but there are errors in my code. Please help me in solving that so that it works fine for large values. </p>
  
  <p>Also, <strong>is my approach right for checking prime number for large numbers without built-in functions?</strong> </p>
  
  <blockquote>
    <p>Other possible solutions/approaches, please.</p>
  </blockquote>
  
  <p>My_Code:</p>
  
  <pre><code>import java.math.*;
  import java.util.Scanner;
  public class CheckPrimeNumber {
      public static void main(String[] args) 
      {
          int flag=0;
          BigInteger input;
          try{
          Scanner sc= new Scanner(System.in);
          System.out.println("Enter a valid positive number: ");
          String strinput=sc.nextLine();
          input = new BigInteger(strinput);
  
          sc.close();
          if(input.equals(0) ||input.equals(1)){                      
            System.out.println(input+" is not a prime number.");
              }
          else{
              for(BigInteger i=2; i &lt; input.divide(2); i++){  
                  if(input.remainder(2) == 0){
                      System.out.println(input+" is not a prime number.");
                      flag=1;
                      break;                      
                      }
                  }
                  if(flag==0)
                      System.out.println(input +" is a prime number.");               
              }
          }
      catch(Exception e){
          System.out.println("Please enter only valid positive number: ");
          }
      finally{
          System.out.println("Thank you...!!!");      
          }
      }
  }
  </code></pre>