import java.util.Scanner;
class demo1
{
public static void main(String args[])
{
int temp;
boolean PrimeNumber=true;
Scanner scan= new Scanner(System.in);
System.out.println("Enter any number:");
int num=scan.nextInt();
scan.close();
for(int i=2;i<=num/2;i++)
{
temp=num%i;
if(temp==0)
{
PrimeNumber=false;
break;
}
}
if(PrimeNumber)
System.out.println(num + " is a Prime Number");
else
System.out.println(num + " is not a Prime Number");
}
}Java
Program to check whether input number is prime or not?

Written by
View ProfileNikhil Juneja
Passionate software developer and technical contributor at TutorialsLink.
