-
Notifications
You must be signed in to change notification settings - Fork 0
/
Problem7
executable file
·47 lines (38 loc) · 869 Bytes
/
Problem7
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
import java.util.*;
public class helloworld {
public static void main(String []args){
//System.out.println("Hello World");
System.out.println("Answer: " + PrimeNum(10001) );
}
public static int PrimeNum (int n) {
Vector<Integer> v = new Vector<Integer>();
v.addElement(new Integer(2));
System.out.println(2);
int i = 3;
while(true) {
System.out.println(i);
if (i % 2 != 0) {
if (checkPrime(i, v)) {
v.addElement(new Integer(i));
if (v.size() == n) {
break;
}
}
}
i++;
}
return ((Integer)v.lastElement()).intValue();
}
public static boolean checkPrime(int i, Vector<Integer> vect) {
if (vect.capacity() == 0) {
return true;
}
else
for (Object obj: vect) {
if (i % ((Integer)obj).intValue() == 0) {
return false;
}
}
return true;
}
}