[Solved] 1 – 100 prime or not in Java


You have almost all of the code correct, you just need to put it in the right place. For example, your println statements need to be inside the for loop and your for loop needs to start at 1 and increment by 1 to 100.

for(int x = 0; x < 101; x++) 
{
   if(x == 2)
      System.out.println(x + " is a prime number");
   if(x % 2 == 0)
      System.out.println(x + " is not a prime number);
   else
      System.out.println(x + " is a prime number);
}

I just helped a friend with almost this exact problem, so this couldn’t be better timing. I don’t know if your scanner is going to be used, but this works if you are just looking for prime numbers from 1-100.

solved 1 – 100 prime or not in Java