Saturday, February 11, 2017

Java Program to enter a number & check whether it is prime no or not.

Note: A Prime number is a natural number which is greater than 1 and that has no positive divisor
other than 1 & itself.
Ex :- 2,3,5,7,11,13,17,19,23......
*/
import static java.lang.System.out;
import java.util.Scanner;
class Prime
{
static public void main(String...alt)
{
Scanner sc=new Scanner(System.in);
out.print("Enter a Number : ");
int n=sc.nextInt();
int flag=0;
for(int i=2;i<=n/2;i++)
{
if(n%i==0)
{
flag=1;
break;
}
}
if(flag==0)
out.println(n+" is prime Number");
else
out.println(n+" is Not prime Number");
}
}

Share this

0 Comment to "Java Program to enter a number & check whether it is prime no or not."

Post a Comment