Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Fills the array with the first array.length prime numbers;
- // assumes that each array entry at an index below n is already correctly set.
- private static void primes(int[] array, int n) {
- if (n < array.length) {
- if (n == 0) {
- array[0] = 2;
- primes((array), (n+1));
- } else {
- int check = array[n - 1];
- boolean isPrime;
- do {
- check++;
- isPrime = true;
- for (int i = 0; i < n; i++) {
- isPrime = isPrime && (check % array[i] != 0);
- }
- } while (! isPrime);
- array[n] = check;
- primes((array), (n+1));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement