质数循环查找
1 package day07_addition; 2 3 //范围查找质数 4 public class PrimeNumLoop { 5 public static void main(String[] args){ 6 int counter = 0; 7 int number = 0; 8 9 //2~100循环查找 10 for(int n=2;n<=100;n++){ 11 boolean flag = true; 12 13 //单个数字查找质数 14 for(int i=2;i<n;i++){ 15 if(n%i == 0){ 16 flag = false; 17 break; 18 } 19 } 20 //判断质数 21 if(flag){ 22 System.out.print(n+" "); 23 counter++; 24 number++; 25 } 26 if(counter%10 == 0){ 27 System.out.println(); 28 } 29 } 30 System.out.println(); 31 System.out.println("共计:"+number); 32 } 33 }