求质素

/**
     * 求质数
     * @param left
     * @param right
     */
    static void checkPrime(int left,int right){
        int count = 0;
        
        for (int i = left; i <= right; i++) {
            boolean flag = true;
            for (int j = 2; j <= Math.sqrt(i); j++) {
                if(flag){
                    if (i%j==0) {
                        flag = false ;
                    }
                }
            }
            if (flag) {
                count++;
                System.out.print(i+" ");
            }
        }
    }

 

posted @ 2016-02-16 15:36  phyxis_xu  阅读(123)  评论(0编辑  收藏  举报