我是偶哦
import javax.swing.*;
public class Test {
public static boolean isPrime(int a) {
boolean flag = true;
if (a < 2) {
return false;
} else {
for (int i = 2; i <= Math.sqrt(a); i++) {
if (a % i == 0) {
flag = false;
break;
}
}
}
return flag;
}
public static void main(String[] args) {
String number = JOptionPane.showInputDialog("请输入:");
boolean result = isPrime(Integer.valueOf(number));
JOptionPane.showMessageDialog(null, result);
}
}