public class OutputDemo1 {
public static void main(String[] args) {
int x,y;
int count=0;
for(x=2;x<=500;x++) {
boolean flag=true;
for(y=2;y<x;y++) {
if(x%y==0) {
flag=false;
break;
}
}
if(flag) {
count++;
if(count<=50)
System.out.print(y+"\t");
if(count%5==0)
System.out.println();
}
}
}
}
按照每行5个数,输出前50个素数。
最新推荐文章于 2023-06-23 01:19:02 发布