class PrimeNo
{
public static void main(String[] args) /*String []args will take
input from the terminal(cmd command line) directly */
{
int n;
for(int i=0;i<args.length;i++) /* using length function to get the total
length of the one dimensional array*/
{
int j=2;
n=Integer.parseInt(args[i]); /*using parseInt function
from Integer class to convert the
numbers (which are in String) into the integer*/
for(;j<=Math.sqrt(n);j++)
{
if(n%j==0)
break;
}
if(j>Math.sqrt(n))
System.out.println(n+" = Prime Number");
else
System.out.println(n+" = Not Prime Number");
}
}
}
No comments:
Post a Comment