The example of this article tells the way Java lists all prime numbers between 2 to 100. Share it for everyone for your reference. The specific implementation method is as follows:
//Testprime.java:public class testprime {public static boyan isprime (int Num) {for (int i = 2; i <= math.sqrt (num); I ++) {// Program default 2 is a prime number, when j is a prime number, when j is a prime number, when = At 2 o'clock, the cycle does not execute if (num % i == 0) {return false;}} Return True;} Public Static void Main (string [] args) {for (int j = 2; j <<= 100; j ++) {if (testprime.isprime (j)) {system.out.println (j + "is a prime");}}}}}}It is hoped that this article is helpful to everyone's Java program design.