Hi, I'm doing an exercise. I'm iterating through numbers from 2 to 100 (since 1 is not a prime number) and I need to test if the current number is a prime, if it is print it out. But I can't figure out the condition, how to test if a number is prime? So far I got this, but it prints all subsequent numbers, which is now obvious to me, but how to test for primes?
public class Main {
public static void main(String[] args) {
for (int i = 2; i <= 100; i++) {
//Test if a number is a prime, if it is print it
// The (i + 1) is because I want to divide i by any other number, so I thought i + 1
if (((i % i) == 0) && ((i % 1) == 0) && ((i % (i + 1)) > 0)) {
System.out.println(i);
}
}
}
}