1 回答
我是偶哦
TA贡献10条经验 获得超3个赞
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); } }
添加回答
举报
0/150
提交
取消