最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Java判断101-200之间有多少个素数并输出
时间:2022-06-29 01:39:09 编辑:袖梨 来源:一聚教程网
程序分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除, 则表明此数不是素数,反之是素数。
程序设计:
| 代码如下 | 复制代码 |
publicclassexp2{ publicstaticvoidmain(String args[]){ inti=0; math mymath =newmath(); for(i=2;i<=200;i++) if(mymath.iszhishu(i)==true) System.out.println(i); } } classmath { publicintf(intx) { if(x==1|| x==2) return1; else returnf(x-1)+f(x-2); } publicbooleaniszhishu(intx) { for(inti=2;i<=x/2;i++) if(x %2==0) returnfalse; returntrue; } } | |
相关文章
- 致命公司铲子可攻击怪物类型汇总 12-05
- 星球重启20级头盔制作方法详解 12-05
- 星球重启分解废品任务完成方法 12-05
- 星球重启偶像任务攻略 偶像任务过法 12-05
- 星球重启9个酸液腺体获取攻略 12-05
- 星球重启采集工具制作方法 采集工具怎么做 12-05