/** * The main method. * * @param args the arguments */ public static void main(String[] args) { int n; if (args.length != 1) { System.out.println("Incorrect usage. Exiting..."); printCorrectUsage(); System.exit(1); } try { n = Integer.parseInt(args[0]); SieveOfEratosthenes sieve = new SieveOfEratosthenes(n); sieve.printPrimes(); } catch (NumberFormatException nfe) { System.out.println(args[0] + " is not a number. Exiting..."); printCorrectUsage(); System.exit(1); } }
public static void main(String[] args) { int primeList[] = SieveOfEratosthenes.findPrimes(2000000); long sum = 0; for (int i = 0; i < primeList.length; i++) sum += primeList[i]; System.out.println(sum); }