[Solved] Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 20 [duplicate]


That means that you try to access A[20] even though it doesn’t exist

When i equals 19, the following line becomes a problem:

A[i] = A[i + 1] + K;

Use 19 insead of 20 in your loop and it should be fine. You need to decide what to do with A[19] though, as it’s value won’t change.

10

solved Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 20 [duplicate]