📜  质数的 ArrayList - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:43.586000             🧑  作者: Mango

代码示例1
import java.util.*;

public class test {
    public static void main(String[] args) {
        System.out.println(primeFinder(13));
    }

    public static ArrayList primeFinder(int n) {
        ArrayList integerArray = new ArrayList();
        
        for (int i = 1; i <= n; i++) {
            int count = 0;
            for (int j = i; j >= 1; j--) {
                if (i % j == 0) {
                    count++;
                }
            }
            if (count == 2) {
                integerArray.add(i);
            }
              
        }
        return integerArray;
    }
}