黑马程序员技术交流社区

标题: 判断101-200之间有多少个素数,并输出所有素数。 [打印本页]

作者: 13770310447    时间: 2016-3-24 00:38
标题: 判断101-200之间有多少个素数,并输出所有素数。
判断101-200之间有多少个素数,并输出所有素数。
作者: cohle1992    时间: 2016-3-24 12:46
public class find {
       public static void main(String[] args) {
    int count = 0;
    for(int i=101; i<200; i+=2) {
     boolean b = false;
     for(int j=2; j<=Math.sqrt(i); j++)
      {
        if(i % j == 0) { b = false; break;
       }
          else
           {
            b = true;
           }
     }
        if(b == true) {count ++;System.out.println(i );
   }                                 
   }
    System.out.println( "素数个数是: " + count);
  }
}




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2