-
Notifications
You must be signed in to change notification settings - Fork 0
/
NthPrime
62 lines (49 loc) · 916 Bytes
/
NthPrime
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package problem.solving;
/**
*
* @author gowtham pr
*
* Find Nth Prime Number
*/
public class NthPrime {
public static void main(String[] args) {
long limit = Integer.MAX_VALUE;
long counterC = 0;
for (long i = 2; i <= limit; i++) {
int counter = 0;
for (long num = i; num >= 1; num--) {
if ((i % num == 0)) {
counter = counter + 1;
}
}
if (counter == 2 && counterC < 10001) {
System.out.println(i);
counterC++;
}
}
}
public void th_prime() {
int counter = 10001;
int n = counter;
for (int i = 2; i <= n; i++) {
boolean isPrime = false;
int y = -1;
for (int j = 2; j <= n; j++) {
if ((i % j == 0) && (j < i)) {
y = -1;
isPrime = false;
break;
} else {
y = i;
isPrime = true;
}
}
if (y != -1 && counter != 0) {
n--;
System.out.println(y);
} else {
break;
}
}
}
}