You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Source: https://www.w3resource.com/java-exercises/math/java-math-exercise-20.php
public class GeneratePrimes {
public static int [] generatePrimes(int num) {
boolean[] temp = new boolean[num + 1];
for (int i = 2; i * i <= num; i++) {
if (!temp [i]) {
for (int j = i; i * j <= num; j++) {
temp [i*j] = true;
}
}
}
int prime_nums = 0;
for (int i = 2; i <= num; i++) {
if (!temp [i]) prime_nums++;
}
int [] all_primes = new int [prime_nums];
int index = 0;
for (int i = 2; i <= num; i++) {
if (!temp [i]) all_primes [index++] = i;
}
return all_primes;
}
}
This error was raised:
The text was updated successfully, but these errors were encountered:
When running this java code:
This error was raised:
The text was updated successfully, but these errors were encountered: