package cn;
public class lianxi02 {
public static void main(String[] args) {
int count=0;//计算素数的次数
boolean num=false;
for(int i=101;i<200;i+=2){//让i为奇数
for(int j=2;j<=Math.sqrt(i);j++){
if(i%j==0){//说明不是素数
num=false;break;//跳出内层循环,执行下一次外层循环
}
else{num=true;}//i%j!=0
}
if(num==true){
count++;
System.out.println (i);
}
}
System.out.println("总共有:"+count+"个素数");
}
}
public class lianxi02 {
public static void main(String[] args) {
int count=0;//计算素数的次数
boolean num=false;
for(int i=101;i<200;i+=2){//让i为奇数
for(int j=2;j<=Math.sqrt(i);j++){
if(i%j==0){//说明不是素数
num=false;break;//跳出内层循环,执行下一次外层循环
}
else{num=true;}//i%j!=0
}
if(num==true){
count++;
System.out.println (i);
}
}
System.out.println("总共有:"+count+"个素数");
}
}
解决方案 »
- 怎么实现 帮个忙啊
- 上传图片显示不出来路径发现含有空格文件夹名的,空格都用“%20”编译,现转化
- struts或J2EE中关于编码规范的讨论
- 有什么好的方法去掉字符串里的',' 吗?
- displaytag如何打印
- log4j输出位置
- 【新手】spring的事物处理正确吗?应该怎么的
- 急需您的帮助:在有状态SessionBean中调用CMP出错,请问该怎么调用?
- 怎么样激活个人的Blog ,我也想留点"历史"下来:)
- Tomcat5下的Servlet汉字出错乱码???,如何解决?
- 用Hibernate3.3.2 this.hibernateTemplate.find查询list返回的都是空元素,求大神
- 关于JAVA做网站的问题,求帮忙
要不然还得多循环。