26 lines
502 B
Java
26 lines
502 B
Java
package Course_Codes;
|
||
|
||
import java.util.Scanner;
|
||
|
||
public class 素数的判断 {
|
||
|
||
public static void main(String[] args) {
|
||
Scanner sc=new Scanner(System.in);
|
||
while(sc.hasNext()) {
|
||
int n=sc.nextInt();
|
||
System.out.println(isprime(n)?"Yes":"No");
|
||
}
|
||
}
|
||
public static Boolean isprime(int n) {
|
||
//排除特殊情况:0 1
|
||
if(n<1)
|
||
return false;
|
||
//i*i<n 无需从2——n全部遍历,只需遍历其一半即可,
|
||
for(int i=2;i*i<n;i++)
|
||
if(n%i==0)
|
||
return false;
|
||
return true;
|
||
}
|
||
|
||
}
|