public class PrimeNumber {
public static void main(String[] args) {
System.out.println("input numbers:");
Scanner scan = new Scanner(System.in);
int num = scan.nextInt();
int flag = 1;
for (int i = 2; i < (num / 2); i++) {
if (num % i != 0) {
flag = 1;
} else {
flag = 0;
}
}
if (flag == 1) {
System.out.println(num + "是质素!!");
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.print("请输入一个整数:");
sc = new Scanner(System.in);
int a = sc.nextInt();
boolean f = Brute_Force(a);
System.out.println(a + "是否为质素(素数):" + f);
}
public static boolean Brute_Force(int n) {
if(n!=1){
for (int i = 2; i <= Math.sqrt(n); i++){
if (n % i == 0){
return false;
}
}
return true;
}else{
return false;
}
}