Program to Test the Prime num

Program to Test the Prime num:-
A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself. For example, 5 is prime, as only 1 and 5 divide it, whereas 6 is Not prime, since it has the divisors 2 and 3 in addition to 1 and 6. so if you test all numbers between 2 and number, and none of them are exactly divisible then it is a prime, otherwise it is not

import java.util.*;
class prime
{
public static void main(String args[])
{ int flag,x,i;
flag=0;
int a[]=new int[7];
for(x=0;x<args.length;x++)
{
a[x]=Integer.parseInt(args[x]);
for(i=2;i<(a[x]/2);i++)
{
if((a[x]%i)==0)
{
break;
}
else flag=1;
}
if(flag==1)
System.out.println(a[x]+" is a prime no ");
else
System.out.println(a[x]+" is not a prime no ");
flag=0;
}
}
}

Related Posts