package 专题练习; public class search_for_primenumbers { public static void main(String[] args) { find_primer(); } //第一题:判断101到200之间有多少个素数,并输出所有素数 public static void find_primer() { int count = 0; //除了1和本身能被其整除为素数 int sign = 0; for (int i = 101; i <= 200; i++) { sign = 0; for (int j = 2; j < i / 2; j++) { if (i % j == 0) { sign = 1; break; } } if (sign == 0) { count++; System.out.print(i + " "); } } System.out.println("有" + count + "个素数"); } }