**Find Number is Prime or Not using Java Program**

**What is Prime Number?**

A prime number is a positive integer which is divisible by itself and only 1

**Steps to check prime number**

- Accept the number from user ans store it into the
**n** variable
- Start the loop from 2 and check number
**n** is divisible by loop variable or not.
- if by any of the number the
**n** is divisible, then update flag value to 1 and stop the loop.
- check if flag = 1 then display number is not prime.
- check if flag = 0 then display number is prime.

See the following flowchart to clearly understand the working of loop to find out number is prime or not.

**Flowchart**

**Example - Program to check given number is prime or not**

import java.util.Scanner;
public class PrimeNumberEx
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
int n,i,flag;
i = 2; flag = 0;
System.out.print("Enter any number : ");
n = scan.nextInt();
while(i<=n/2)
{
if(n%i == 0)
{
flag = 1;
break;
}
i = i + 1; // or i += 1;
}
if(flag==0)
System.out.print(n+" is a prime number");
else
System.out.print(n+" is Not prime number");
}
}

**Output**

Enter any number : 11

11 is a prime number