您的位置:首页 > 其它

求1000以内的素数

2018-03-29 23:08 162 查看
求1000以内的素数:
package com.zrrd;

public class SuShu {

public static void main(String[] args) {
//求1000以内的素数
System.out.print(1+"\t");
System.out.print(2+"\t");
int count=2;
for (int i = 3; i <=1000; i++) {
boolean b=true;
for (int j = 2; j < Math.pow(i, 0.5)+1; j++) {
if (i%j==0) {
b=false;
}
}
if (b) {
System.out.print(i+"\t");
count++;
}
//每10个素数切换一行
if (count==10) {
System.out.println();
count=0;
}
}

}

}输出结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: