Since in java the first position of an array is 0, if an array has
length 3 then the last element is in position 2.
Ex: array = [elem0, elem1, elem2] then the last elem is index 2
and the array has length 3
check the code if it is accesing the element at negative index