判断101-200之间的素数

 1 /*【程序2】
 2 题目:判断101-200之间有多少个素数,并输出所有素数。
 3 判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除,
 4 则表明此数不是素数,反之是素数。 */
 5 
 6 public class SecondPrimeNumber {
 7     public static int count=0;
 8 public static void main(String[] args) {
 9     for(int i=101;i<200;i++) {
10         boolean b=true;
11         for(int j=2;j<Math.sqrt(i);j++) {
12             if(i %j==0)
13                 b=false;
14         }
15             
16         if(b) {
17             count++;
18             System.out.print(i+" ");
19         }
20     }
21     System.out.println("\n素数的个数"+count);
22     
23 }
24 }

 

posted @ 2018-03-28 15:51  岳婷077  阅读(569)  评论(0编辑  收藏  举报