判断一个数是否为素数
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int n = input.nextInt();
boolean result = su( n);
if(result == true)
System.out.print("素数");
else
System.out.print("不是素数");
}
public static boolean su(int a) {
if(a == 1)
return false;
if(a % 2 == 0 && a != 2)
return false;
for(int i = 3; i < Math.sqrt(a); i+=2) {
if(a % i == 0)
return false;
}
return true;
}
}