Applying "Ehrlich's sieve method" in JAVA program

    The following is a program for asking for prime numbers. Please correct me and speak your mind.
     Note:

  • Among them, the "Ehrlich's sieve method" is used to obtain a prime number within 2 to 10,000.
  • After testing, it is ready for normal operation.

    以下是一个求素数的程序,请大家指正,畅所欲言。
  注释:

  • 其中运用了“埃氏筛法”求2~10000以内的素数。
  • 经测试,已可以正常运行。





package com.JamesC;

class PrimeNumber{
   public static void main(String[] arguments){
            int n = 10000;
            int[] a = new int[10000];
        boolean[] mark = new boolean[n+1];//Tick.
         for(int i=2;i<=n;i++){
            mark[i] = true;
        }

        for(int i=2;i<=Math.sqrt(n);i++){
            if(mark[i] == true){
                for(int j = i;j*i<=n;j++){
                    mark[i*j] = false;
                }
            }
        }

        int d=0;
        for(int i = 2;i<=n;i++){
            if(mark[i] == true){
                d++;
                System.out.print(i + " ");
                if(d%10 == 0){
                    System.out.println();
                }    
            }
        }
    }
}    
        

Comments