/* * Prints the first 100 prime numbers * using the Sieve of Eratosthenes */ class Sieve { public static void main(String[] args) { final int MAX = 100; boolean[] crossedOut = new boolean[MAX]; // elements are initialized to false for (int n = 2; n < MAX; n++) { if (crossedOut[n]) continue; else { System.out.println(n); int i = n; while (i < MAX) { crossedOut[i] = true; i = i + n; } } } } }