package stone; public class PrimerNumber { public static void main(String[] args) { int MAX_NUMBER = 100; boolean[] notPrimer= new boolean[MAX_NUMBER]; for(int i=2;i<=MAX_NUMBER;i++){ if(!notPrimer[i-1]){ for(int j=2*i;j<=MAX_NUMBER;j++){ if(j%i==0) notPrimer[j-1]=true; } } } for(int i=0;i<MAX_NUMBER;i++){ if(!notPrimer[i]) System.out.print(i+1+" "); } } } 运行结果如下: 1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97