Jim Gallagher wrote:... The index is either negative or greater than or equal to the size of the array.
The entries of an array of size n are numbered from 0 to n-1, is what that means. So if you attempt to use entry number n (which is what your error message says you did for n=100), you'll get an error.
I can see that your while-loop at lines 22 to 25 in your posted code has the potential of trying to set A[n] to zero -- I can't explain why it doesn't always try to set A[n] to zero but at any rate that code has a problem.
(I think that the only values of n for which the error doesn't occur are squares of primes, I suppose it might be interesting to find out if that's true but in your case it would be more useful to fix the problem.)
Lasagna is spaghetti flvored cake. Just like this tiny ad:
create, convert, edit or print DOC and DOCX in Java