Public class prime public static void main(String[] args) int n = Integer.parseInt(args); int primesFound=0; if (n==1) System.out.println("1st prime is: "+2);return; if (isPrime(current)) primesRemain--; if / / not prime return
Copyright:
Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online from Scribd
Public class prime public static void main(String[] args) int n = Integer.parseInt(args); int primesFound=0; if (n==1) System.out.println("1st prime is: "+2);return; if (isPrime(current)) primesRemain--; if / / not prime return
Public class prime public static void main(String[] args) int n = Integer.parseInt(args); int primesFound=0; if (n==1) System.out.println("1st prime is: "+2);return; if (isPrime(current)) primesRemain--; if / / not prime return
Copyright:
Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online from Scribd
Public class prime public static void main(String[] args) int n = Integer.parseInt(args); int primesFound=0; if (n==1) System.out.println("1st prime is: "+2);return; if (isPrime(current)) primesRemain--; if / / not prime return
Copyright:
Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online from Scribd
int n = Integer.parseInt(args[0]); int primesFound=0; if (n==1) {System.out.println("1st prime is: "+2);return;} if (n==2) {System.out.println("2nd prime is: "+3);return;} int current=4; int primesRemain=n-2; while (primesRemain > 0) { current++; if (isPrime(current)) { primesRemain--; } } System.out.println(n+"th prime is: "+current); } public static boolean isPrime(int n) { double sqrt = Math.sqrt(n); for(int divisor=2; divisor<=sqrt; divisor++) { if ((n%divisor)==0) { //not prime return false; } } return true; } }