public class One {
/**
* 输出101 - 200之间所有的素数:
* 素数:只能被1和它本身整除的数
*/
public static void main(String[] args) {
sushu(101, 200);
}
static void sushu(int begin, int end) {
int count = 0;
for(int i = begin; i <= end; i++) {
boolean flag = true;// 假设是素数
for(int j = 2; j <= i /2; j++) {
if(i % j == 0) {
flag = false;
break;
}
}
if(flag) {
count++;
System.out.print(i+"\t");
if(count % 5 == 0) {
System.out.println();
}
}
}
}
}
求101 ~ 200 之间的素数
最新推荐文章于 2022-12-07 12:41:58 发布