@@ -0,0 +1,1032 @@
+public class Prime %7B%0A  private Prime() %7B %7D%0A%0A  public static void printPrimes(int max) %7B%0A    boolean%5B%5D flags = sieveOfEratosthenes(max);%0A    System.out.println(%22== Primes up to %22 + max + %22 ==%22);%0A    for (int i = 0; i %3C flags.length; i++) %7B%0A      if (flags%5Bi%5D) %7B%0A        System.out.println(%22* %22 + i);%0A      %7D%0A    %7D%0A  %7D%0A%0A  public static boolean%5B%5D sieveOfEratosthenes(int max) %7B%0A    boolean%5B%5D flags = new boolean%5Bmax + 1%5D;%0A    // initialize flags except 0 and 1%0A    for (int i = 2; i %3C flags.length; i++) %7B%0A      flags%5Bi%5D = true;%0A    %7D%0A%0A    int prime = 2;%0A    while (prime * prime %3C= max) %7B%0A      crossOff(flags, prime);%0A      prime = getNextPrime(flags, prime);%0A    %7D%0A%0A    return flags;%0A  %7D%0A%0A  private static void crossOff(boolean%5B%5D flags, int prime) %7B%0A    for (int i = prime * prime; i %3C flags.length; i += prime) %7B%0A      flags%5Bi%5D = false;%0A    %7D%0A  %7D%0A%0A  private static int getNextPrime(boolean%5B%5D flags, int prime) %7B%0A    int next = prime + 1;%0A    while (next %3C flags.length && !flags%5Bnext%5D) %7B%0A      next++;%0A    %7D%0A    return next;%0A  %7D%0A%7D%0A

add primes