Wednesday, February 18, 2015

Java program to check whether a number is prime or not

Java program to check whether a number is prime or not

class prime
{
public static void main(String...s)
{
int n,i;
n=Integer.parseInt(s[0]);

for(i=2;i<n;++i)
{
if(n%i==0)
break;
}

if(i==n)
System.out.println("
Number is prime");

else
System.out.println("
Number is not prime");

}
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.