- public class ZhiShu {
- /*
- * 2.编程打印所有的3位质数,质数特点:只能被1和其本身整除
- *
- */
- public static void main(String[] args) {
- int n = 100;
- int count=0;
- for (int i = 100; i < 1000; i++) { //遍历所有的三位数
- for (int j = 2; j <= i/2; j++) { //遍历所取的三位数的一半
- if (i%j == 0) { //该三位数从2开始到它的一半 看能否整除
- break;
- }else{
- if(j == i/2){
- System.out.print(i + " ");
- count++;
- if(count == 10){
- System.out.println();
- count=0;
- }
- }
- continue;
- }
- }
- }
- }
- }
复制代码
|
|