题目:判断100-200之间有多少个素数,并输出所有素数。
public class zhiShu {
public static int count =0;
public static void main(String[] args) {
for(int i=100;i<200;i++){
for(int j=2;j<=i;j++){
if (i % j==0){
if (j>=i){
count++;
System.out.println(i+" ");
}else{
break;
}
}
}
}
System.out.println("素数的个数:"+count);
}
控制台打印语句
101
103
107
109
113
127
131
137
139
149
151
157
163
167
173
179
181
191
193
197
199
素数的个数:21