hey..everything is allright until if(n%x==0)
all u got to do is:
for(x=1;x<=n;x++)
{
if(n%x==0)
counter++;
}
if(counter==1)
{
System.out.println("prime number");
else
System.out.println("composite number");
}
its more simpler...according to me...
the mistake was....inside the for loop...u are increasing the counter...
but u are checking for the prime number before the whole loop executes....
u can obtain the value of the counter only after it checks for the remainder of each and every number until the input number...
i think it is the mistake,....i have tried my best to explain...if anything i said was wrong...please correct me....