最新下载
热门教程
- 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; } } | |
相关文章
- 飞猪客服电话是多少-飞猪机票24小时人工服务热线 10-15
- Hermes Agent MCP配置指南:从安装到调用Agent工具包全流程完整指南 10-15
- jm浏览器官网进入-jm网页版官方入口 10-15
- erolabs实验室官网登录入口-erolabs实验室官网登录链接直达 10-15
- jm漫画-官方正版网页入口 10-15
- 豆包官网网页版入口-豆包在线使用网页版 10-15