1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| package code;
public class Prame {
public static void main(String[] args) { int a,b; a=0; b=0; for (int i = 101; i <= 200; i++) { for(int j = 2; j < i; j++) { if( i%j == 0 ) a++; } if ( a < 1 ) { b++; System.out.println(i); a = 0; } else a = 0; } System.out.println("101至200之间有" + b + "个素数"); } }
|