A number which is only divisible by 1 and the number itself is a Prime number.

Program:

import java.util.Scanner;
public class Prime
{
  public static void main(String[] args)
  {
    int i=2;
    Scanner sc = new Scanner(System.in);
    System.out.print("Enter a number bigger than 2: ");
    int a = sc.nextInt();
    for(; i<10; i++)
    { 
      if(a%i==0 && a!=i)
      {
       System.out.println("Entered number "+a+" is not a prime number.");
       break;
      }
    }
    if(i==10)
    {
      System.out.println("Entered number "+a+" is a prime number.");
    }
  }
}

Output:

Enter a number bigger than 2: 6
Entered number 6 is not a prime number.

You can download the pdf file of Prime.

Advertisements