I typed this piece of code for finding all the prime numbers between 0 and 100, but it gives output with multiples of other numbers. How can I rectify this?
public class PrimeNumbers {
public static void main(String[] args) {
int count = 0;
int n = 0;
for (n = 2; count <= 100; n++) {
for (int j = 2; j < n; j++) {
while (n % j == 0) {
j = 2;
n++;
}
}
count++;
System.out.println(n);
}
}
}