判断素数
来源:互联网 发布:mac网速慢的解决办法 编辑:程序博客网 时间:2024/05/19 01:13
import java.util.*;/** * @author besty_wang * @version 创建时间:2016年8月2日 下午6:28:11 * 类说明 判断101-200之间有多少个素数,并输出所有素数。 * 判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除, 则表明此数不是素数,反之是素数。 */public class PrimeJudgment {public static void main(String[] args) {int count = 0;List<Integer> list = new ArrayList<Integer>();for (int i = 101; i <= 200; i++) {if (primeJudgment(i)){list.add(i);count++;}}System.out.println("101-200之间有"+count+"个素数");System.out.println(list.toString());}public static boolean primeJudgment(int i) {int a = (int) (Math.sqrt(i));boolean val = true;for (int num = 2; num <= a; num++) {if (i % num == 0) {val = false;break;}}return val;}}
0 0
- 素数判断
- 判断素数
- 判断素数
- 判断素数
- 素数判断
- 判断素数
- 判断素数
- 判断素数
- 判断素数
- 判断素数
- 判断素数
- 素数判断
- 判断素数
- 判断素数
- 判断素数
- 判断素数
- 判断素数
- 判断素数
- oracle中SQL优化的相关问题
- PowerShell中出现”禁止执行脚本“的解决方法
- 四舍五入计算器,第一个python—gui程序
- Excel 阳历转阴历
- ubuntu下的jdk安装
- 判断素数
- Oracle约束操作
- 标准C++中的string类的用法总结
- 2034 人见人爱A-B
- 二分图匹配 ( 多重匹配&&Hungarian)——Escape ( HDU 3605 )
- android自定义title出现 You cannot combine custom titles with other title features
- Android FrameWork源码浅析之(一)--handler,looper,messagequeue
- 进程相关操作
- 移植uboot第三步:修改时钟