- public class Demo5_Prime {
- public static void main(String[] args) {
- System.out.println(getPrime(100));
- }
- public static int getPrime(int max) {
- int count = 0;
- for (int n = 2; n <= max; n++) {
- int i = 2;
- while (i < n) {
- if (n % i == 0)
- break;
- i++;
- }
-
- if (i == n) {
- count++;
- System.out.print(i + "\t ");
- }
- }
- System.out.println();
- return count;
- }
- }
复制代码 |
|