Why does my program return the error "ArrayIndex Out Of Bounds Exception: 4"?

You could use the array length in your loop so even if you change the array size the code will not cause an error.

for(int i = 0; i < genpart.length; i++) {

1 Like