Java Prime Number无限循环:启动更多副本?

时间:2015-07-01 18:10:13

标签: java infinite-loop infinite

我有一个无限循环的素数生成器,如果我是素数,我想启动无限循环素数生成器的更多实例。

代码:

public class asdf4 {

public static void main(String[] args) {

    int least = 0;

    System.out.println("Generate Prime numbers between" + least + " and ");

    // loop through the numbers one by one
    for (int i = 1; i > least; i++) {

        boolean isPrimeNumber = true;

        // check to see if the number is prime
        for (int j = 2; j < i; j++) {
            if (i % j == 0) {
                isPrimeNumber = false;
                break; // exit the inner for loop
            }
        }

        if (isPrimeNumber) {
            //launch 10 more instances

        }
    }

}

}

1 个答案:

答案 0 :(得分:0)

public class PrimeClass {

    public static void startInfiniteLoop(){
        int least = 0;
        System.out.println("Generate Prime numbers between" + least + " and ");

        // loop through the numbers one by one
        for (int i = 1; i > least; i++) {

            boolean isPrimeNumber = true;

            // check to see if the number is prime
            for (int j = 2; j < i; j++) {
                if (i % j == 0) {
                    isPrimeNumber = false;
                    break; // exit the inner for loop
                }
            }

            if (isPrimeNumber) {
                for (int j = 0; j < 10; j++)
                    PrimeClass.startInfiniteLoop();
            }
        }
    }
}