输出1到n以内的素数

package cn.lhj.learn;

/**
 * 输出1~n以内的素数
 * 
 * @author lhj
 *
 */
public class TestSuShu {

    public static void main(String[] args) {
        for (int i = 2; i <= 100; i++) {
            if (find(i)) {
                System.out.print(i + " ");
            }
        }
    }

    public static boolean find(int n) {
        for (int i = 2; i < Math.sqrt(n); i++) {
            if (n % i == 0) {
                return false;
            }
        }
        return true;
    }

}

原文地址:https://www.cnblogs.com/linhuanjie/p/7805779.html