Skip to content

Instantly share code, notes, and snippets.

@ellbur
Created October 12, 2011 04:25
Show Gist options
  • Save ellbur/1280267 to your computer and use it in GitHub Desktop.
Save ellbur/1280267 to your computer and use it in GitHub Desktop.
Nth prime puzzle
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