判断素数
输入一个大于1的整数x,
若x是素数,则输出Yes,否则输出No
import java.util.Scanner;
public class PrimeNumber {
static boolean IsPrimeNumber(int x) {
for (int i = 2; i <= Math.sqrt(x); i++)
if (x % i == 0) return false;
return true;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int x = in.nextInt();
if (IsPrimeNumber(x)) System.out.println("Yes");
else System.out.println("No");
}
}
标签:输出,判断,java,Scanner,int,素数
From: https://www.cnblogs.com/aruhan/p/17069011.html