public class Forfor { public static void main (String args []){ for(int i = 100 ; i <= 200 ; i++){ boolean a = false ; for(int j = 2 ; j < i - 1 ; j++){ int k = i % j ; if(k == 0){ a = true ; break; } } if(!a){ System.out.println(i); } } } 输出结果: 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 }