Prime Number
public class Main {
public static void main(String[] args) {
for(int i = 2; i <=100; i++) {
if(i == 2 || i == 3 || i == 5 || i == 7) {
System.out.println(i);
} else {
if((i % 2 != 0) && (i % 3 != 0) && (i % 5 != 0) && (i % 7 != 0)) {
System.out.println(i);
}
}
}
}
}
The snippet result is
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
There are 25 prime numbers between 2 to 100 numbers.
Last updated