//1到200的素数及个数,我是新手,大神多多指教!!!
class Test1 {
public static void main(String[] args) {
int i;
int count = 0;
int count1;
for(i= 2;i <= 200;i++) {
count1 = 0;
for (int j = 1;j <=i ;j++ ) {
if (i % j == 0) {
count1++;
}
}
if (count1 == 2 ) {
count++;
System.out.println("素数是:" + i);
}
}
System.out.println("素数的个数是:" + count);
}
}
|
|