What is the number of prime? The number of prime is unable to be removed from 1 and its own number. How to get these numbers? We can start from the minimum prime number 2 until the number of small 1 is smaller than it. If it can be tightened, it is not a prime number, which is the simpler number of judgments. Although this algorithm is the easiest, the time complexity is the largest (see Example 1). Example 1: / ** * Prime.java * Survey the number of individuals smaller than a number * /
Public class princime {
/ * Judgment is the number of prime numbers * / public boolean isprime (int N) {boolean res = true; int i = 0; for (i = 2; i Public static void main (string [] args) {INT n = 100; int i = 0; prime p = new prime (); for (i = 1; i <= n; i ) {i (p.isprime) )) {System.out.println (i);}}}} // is not finished, to be continued!