In this tutorial how to create a program to check a number is prime or composite Core Java is shown.
Code:
PrimeNo.java
class CheckPrime
{
public static void main(String args[])
{
int number=Integer.parseInt(args[0]),i;
if(number==0)
System.out.println(number+” is whole number”);
else if(number==1 || number==2)
System.out.println(number+” is prime number”);
else
{
for(i=2;i<number;i++)
{
if(number%i==0)
{
break;
}
}
if(i==number)
System.out.println(number+” is prime number”);
else
System.out.println(number+” is composite number”);
}
}
}