判断101-200之间有多少个素数,并输出所有素数

如题所述

23个:103、107、109、113、119、127、131、133、137、139、149、151、157、161、163、167、173、179、181、191、193、197、199。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-05-18
public class Su {

 public static void main(String[] args) {

  int su = 0;

  int count = 0;

  for (int i = 101; i < 201; i += 2) {

   if (isSu(i)) {

    su = i;

    System.out.println(su);

    count++;    

   }

  }

  System.out.println(count++);

 }

 public static boolean isSu(int i){

  for (int j = 2; j <= i / 2; j++) {

   if (i % j == 0) {

    return false;

   }

  }

  return true;

  

 }

}

相似回答