posted 1 week ago
I'm trying to implement "The Sieve of Eratosthenes" using the following algorithm/pseudocode "ALGORITHM Sieve(n)".
MY IMPLEMENTATION:
For n = 25, I get an array of all primes less than 25, which is good:
However, if I choose a different value for n (say for example, n = 100) I get the following error message in eclipse:
What do I have to do with my code to avoid the "ArrayIndexOutOfBoundsException" so that all prime numbers less than n are displayed, regardless of n's value.
According to the oracle docs, this error is "Thrown to indicate that an array has been accessed with an illegal index. The index is either negative or greater than or equal to the size of the array."
I'm not sure why it works for 25, but not another number sieve(100).