public class ST_FOR {
public static void main(String[] args) {
System.out.println("Start");
//
System.out.println("------------------------");
//
if(args.length > 0)
{
int nNum = Integer.parseInt(args[0]);
boolean bPrime = true;
//コマンドライン引数の素数判別
for(int i = 2; i < nNum/2; i++)
{
if((nNum % i) == 0)
{
bPrime = false;
}
}
//
if(bPrime == true){
System.out.println(args[0] + " is Prime");
}
else
{
System.out.println(args[0] + " is not Prime");
}
}
else
{
System.out.println("Command Line Error");
}
//
System.out.println("------------------------");
System.out.println("End");
}
}
|