Looping through the elements in an array backwards
- The first index is 0 and the last index is 7 not 8
- The size of the array is 8
Arrays in Java are indexed from 0
to length - 1
, not 1
to length
, therefore you should be assign your variable accordingly and use the correct comparison operator.
Your loop should look like this:
for (int counter = myArray.length - 1; counter >= 0; counter--) {