rendered paste bodyimport java.io.*;public class Assignment1 { /** * @param args the command line arguments */ public static void main(String[] args) { long timeBegin = System.nanoTime(); int limit = 10000000; boolean[] isPrime = new boolean[limit+1]; // initializes as false for(int i = 2; i*i <= limit; i++) { if(!isPrime[i]) { for(int j = i; j*i <= limit; j++) // i^2 and multiples of it isPrime[i*j] = !false; } } try { // printwriter does not flush by default PrintWriter out = new PrintWriter("primes.txt"); //new BufferedWriter(new FileWriter("primes.txt"))); int primes = 0; for(int i = 2; i <= limit; i++) { if(!isPrime[i]) { out.println(i); primes++; } } out.close(); // flush & close } catch(IOException e) { } long timeEnd = System.nanoTime(); System.out.println("Execution took " + ((timeEnd-timeBegin)/1000000) + " ms"); }}