-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrime.java
More file actions
36 lines (30 loc) · 749 Bytes
/
Prime.java
File metadata and controls
36 lines (30 loc) · 749 Bytes
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
class Prime {
static boolean prime(int num) {
if(num < 2)
return false;
if(num == 2)
return true;
if(num%2 == 0)
return false;
for(int i = 3; i < (num/2); i += 2) {
if(num%i == 0)
return false;
}
return true;
}
static int yieldprime(int target) {
int count = 1;
int primes = 2;
while(true) {
if(count == target)
return primes;
primes++;
if(prime(primes))
count++;
}
}
public static void main(String[] argv) {
int prime = yieldprime(Integer.parseInt(argv[0]));
System.out.println(prime);
}
}