WAP to enter a number and check whether it is a prime number or not
Answers
Answered by
3
public class prime
{
public static void main(int n)
{
int i,c=0;
for( i=1; i less than equal to n;i++)
{
if(n%i==0)
{
c++;
}
}
if(c==2)
{
System.out.println("prime");
}
else
{
System. out.println ("not prime");
}
}
}
{
public static void main(int n)
{
int i,c=0;
for( i=1; i less than equal to n;i++)
{
if(n%i==0)
{
c++;
}
}
if(c==2)
{
System.out.println("prime");
}
else
{
System. out.println ("not prime");
}
}
}
Similar questions