forked from damaohongtu/JavaInterview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNthPrime.java
More file actions
38 lines (33 loc) · 901 Bytes
/
NthPrime.java
File metadata and controls
38 lines (33 loc) · 901 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
37
38
package NiuKeWang;/**
* @Classname NthPrime
* @Description TODO
* @Date 19-3-17 上午10:39
* @Created by mao<[email protected]>
*/
import java.util.Scanner;
public class NthPrime {
public static boolean isPrime(int n){
for(int i=2;i<=Math.sqrt(n);i++)
{
if(n%i==0){
return false;
}
}
return true;
}
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
while(in.hasNext()){
int n=in.nextInt();
int count=0;
int i=0;
for( i=2;i<=1000;i++){
if(isPrime(i)){
count++;
}
if(count==n) break;
}
System.out.println(i);
}
}
}