Package Com.test_java;
Import Java.util.Arrays;
public class Prime {* * * * * * * * To find the prime number within n/int n;
int i,j; Prime (int inputn) {this.
N = inputn;
//Normal Trial Division private void Comprime1_1 () {System.out.println ("less than" + N + "prime number has:");
for (i=n;i>=0;i--) {to (j=i-1;j>=2;j--) {if (i%j==0) {break;
} if (j<=2) System.out.println (i);
} System.out.println (2); }//Loop to sqrt (N), simply explain: the factors are in pairs. For example, 100 of the factors are: 1 and 100,//2 and 50,4 and 25,5 and 20,10 and 10. See No.
A pair of factors, one of which must be less than or equal to 100 of the open//squared, and another greater than or equal to 100 of the open squared.
private void Comprime1_2 () {System.out.println ("less than" + N + "prime number has:");
for (int i=n;i>=0;i--) {for (int j=2;j<= (int) math.sqrt (i); j + +) {if (i%j==0) break;
if (j = = (int) math.sqrt (i)) System.out.println (i);
Filter Private boolean[] filternumber (int num) {if (num<=0) {System.out.println ("scope must be greater than 0");
return null;
} boolean[] IsPrime = new Boolean[num + 1];
ISPRIME[1] = false;
Arrays.fill (isprime,2,num,true); Int n = (int) math.sqrt (num);
for (int i=1;i<n;i++) {if (Isprime[i]) {for (int j=2*i;j<=num;j+=i) {isprime[j]= false;
}} return isprime;
private void ComPrime2 () {boolean[] primes= filternumber (N);
int num=0;
if (Primes!=null) {for (int i=1;i<primes.length;i++) {if (primes[i)) {System.out.println (i+ "");
if (++num%10==0) System.out.println ();
} System.out.println ();
} System.out.println ("A total" +num+ "a prime number");
public static void Main (string[] argc) {Prime Prime = new Prime (100);
Prime.comprime2 ();
}
}