Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error running a specific algorithm #37

Open
mateusluizfb opened this issue Mar 23, 2021 · 0 comments
Open

Error running a specific algorithm #37

mateusluizfb opened this issue Mar 23, 2021 · 0 comments

Comments

@mateusluizfb
Copy link
Contributor

When running this java code:

// 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:

Screen Shot 2021-03-11 at 19 58 25

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant