题目:判断101-200之间有多少个素数,并输出所有素数。

1.程序分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除,

则表明此数不是素数,反之是素数。

public class test07 {
public static void main(String[] args) throws NumberFormatException, IOException{
int num=1;
for(int j=101;j<201;j++){
boolean flag=false;
for(int i=2;i<j;i++){
int res=j%i;
if(res==0){
flag=false;
break;
}else{
flag=true;
}
}
if(flag==true){
System.out.println(num+++"zz"+j);}
} } }
public class test07 {
public static void main(String[] args) throws NumberFormatException, IOException{
int num=1;
for(int j=101;j<201;j++){
boolean flag=false;
for(int i=2;i<=Math.sqrt(j);i++){
int res=j%i;
if(res==0){
flag=false;
break;
}else{
flag=true;
}
}
if(flag==true){
System.out.println(num+++"zz"+j);}
} } }

最新文章

  1. sublime text3同时编辑多行
  2. OC基础--self关键字
  3. javamail 发送附件
  4. MySQL: LEAVE Statement
  5. C和指针 第一章 字符串处理程序
  6. mac android studio 编译时报Class JavaLaunchHelper is implemented in both
  7. web.py+mysql插入中文提示query = query.encode(charset) UnicodeEncodeError: &#39;latin-1&#39; codec can&#39;t encode characters in position 86-100
  8. C++库研究笔记——操作符重载实现类型转换&这样做的意义
  9. 08_android入门_android-async-http开源项目介绍及用法
  10. Fiddler 模拟post 提交
  11. leetcode_Search in Rotated Sorted Array II
  12. poj 2299 Ultra-QuickSort 逆序对模版题
  13. Docker Swarm集群
  14. java宜立方商城项目
  15. 2018 ACM-ICPC, Syrian Collegiate Programming Contest
  16. C# Invoke方法
  17. [UI] 05 - Bootstrap: built-in components
  18. 关于linux-Centos 7下mysql 5.7.9的rpm包的安装方式
  19. Hadoop概念学习系列之谈hadoop/spark里分别是如何实现容错性?(四十二)
  20. ReactNative WebView组件详解

热门文章

  1. iOS获取运营商的相关信息
  2. ios - 图片自动轮播定时器(NSTimer)以及消息循环模式简介
  3. my ambition
  4. Java-NIO-Selector
  5. Leetcode: Count Numbers with Unique Digits
  6. JaveScript——简介、语法
  7. 最大权闭合图最大获益(把边抽象为点)HDU3879
  8. hduoj 4708 Rotation Lock Puzzle 2013 ACM/ICPC Asia Regional Online —— Warmup
  9. [转] linux中pam模块
  10. java中时间的比较