Created
October 12, 2011 04:25
Nth prime puzzle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Primes { | |
public static void main(String[] args) { | |
int n = 34; | |
int count = 0; | |
// for (int k=2; ; k++) { | |
int k = 2; | |
while (true) { | |
boolean isPrime = true; | |
// for (int j=2; j<k; j++) { | |
int j = 2; | |
while (j < k) { | |
if (k % j != 0) { | |
} | |
else { | |
isPrime = false; | |
break; | |
} | |
j++; | |
} | |
if (isPrime) { | |
count++; | |
} | |
if (count == n) { | |
System.out.println(k); | |
return; | |
} | |
k++; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment