判断101-200之间有多少个素数,并输出所有素数。
2017-05-22 17:16
344 查看
public static void main(String[] args) {
// TODO Auto-generated method stub
//判断101-200之间有多少个素数,并输出所有素数。
//素数:只能被1和他自身整除的的数
int count = 0;//用来统计素数的个数
for (int i = 101; i <= 200; i++) {
boolean b = false;
//Math.sqrt(double a)方法:返回正确舍入的 double 值的正平方根。
for (int j = 2; j <Math.sqrt(i); j++) {
if(i%j==0){
b = false;
break;
}else{
b = true;
}
}
if(b==true){
count++;
System.out.print(i+" ");
}
}
System.out.println("\n"+"素数的个数为:"+count+"个");
}
// TODO Auto-generated method stub
//判断101-200之间有多少个素数,并输出所有素数。
//素数:只能被1和他自身整除的的数
int count = 0;//用来统计素数的个数
for (int i = 101; i <= 200; i++) {
boolean b = false;
//Math.sqrt(double a)方法:返回正确舍入的 double 值的正平方根。
for (int j = 2; j <Math.sqrt(i); j++) {
if(i%j==0){
b = false;
break;
}else{
b = true;
}
}
if(b==true){
count++;
System.out.print(i+" ");
}
}
System.out.println("\n"+"素数的个数为:"+count+"个");
}
相关文章推荐
- 判断101-200之间有多少个素数,并输出所有素数。
- 题目:判断101-200之间有多少个素数,并输出所有素数。
- 判断101-200之间有多少个素数,并输出所有素数
- 判断101-200之间有多少个素数,并输出所有素数。
- 【程序2】判断101-200之间有多少个素数,并输出所有素数。
- Java笔试常见编程题目:判断101-200 之间有多少个素数,并输出所有素数
- 判断101-200之间有多少个素数,并输出所有素数。
- [Java]练习题002: 判断101-200之间有多少个素数,并输出所有素数
- 判断101-200之间有多少个素数,并输出所有素数
- 判断101-200之间有多少个素数,并输出所有素数。
- 06_判断101-200之间有多少个素数,并输出所有素数
- 大三学长带我学习JAVA.作业8。 判断101-200之间有多少个素数,并输出所有素数。
- 判断101-200之间有多少个素数,并输出所有素数。 程序分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除, 则表明此数不是素数,反之是素数。
- 题目:判断101-200之间有多少个素数,并输出所有素数。
- 判断101-200之间有多少个素数,并输出所有素数
- 判断101-200之间有多少个素数,并输出所有素数及素数的个数
- 判断101-200之间有多少个素数,并输出所有素数 Java实现
- 判断101-200之间有多少个素数,并输出所有素数。
- 判断101-200之间有多少个素数,并输出所有素数。
- 判断101-200之间有多少个素数,并输出所有素数。