linux将数组中质数放前面,用数组求前100个素数

你的逻辑有点错误,根据你的计算思路,我自己写了一个;;;;

public class demo01 {

public static void main(String[] args) {

int num=3;

int numcalled=0;

System.out.print(2+"\t");

for(numcalled=0;numcalled<99;){

boolean flag=false;

for(int j=2;j

if(num%j==0){

flag=false;

break;

}else{

flag=true;

j++;

}

}

if(flag==true){

numcalled++;

if(numcalled%10==0){

System.out.println();

}

System.out.print(num+"\t");

}

num++;

}

}

}

控制台输出结果如下:

2357111317192329

31374143475359616771

7379838997101103107109113

127131137139149151157163167173

179181191193197199211223227229

233239241251257263269271277281

283293307311313317331337347349

353359367373379383389397401409

419421431433439443449457461463

467479487491499503509521523541

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值