the fibonacci sequence has a negative number duplicated

You cannot go up to index= 4000 in this loop, you have integer overflowed. Maximum you can go to is 49. Change the loop as such.

for(int i = 2 ; i < 49 ; i ++){
            n3 = n1 + n2;
            fibonacci.add(n3);
            n1=n2;
            n2=n3;
        }

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top