码迷,mamicode.com
首页 > 其他好文 > 详细

求101~200之间素数的个数并将其打印

时间:2015-08-01 11:15:05      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:

//判断101~200之间有多少个素数,并输出所有素数,并每8个为一行对齐

public class FenDou02 {

  public static void main(String[] args) {
    System.out.println("101~200的所有素数为:");
    int count=0;
    for(int i=101;i<200;i+=2){
      int j=2;
      for(j=2;j<i/2;j++){
        if(i%j==0){
          break;
        }
      }
      if(j==i/2){
        count++;
        System.out.print(i+" ");
        if(count%8==0){
          System.out.println();
        }
      }
    }
  }

}

 

求101~200之间素数的个数并将其打印

标签:

原文地址:http://www.cnblogs.com/changyinlu/p/4693730.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!