This book is now obsolete Please use CSAwesome instead.
8.7. Common MistakesΒΆ
forgetting to create the array - only declaring it (
int[ ] nums;
)using 1 as the first index not 0
using
array.length
as the last valid index in an array, notarray.length - 1
.using
array.length()
instead ofarray.length
(not penalized on the free response)using
array.get(0)
instead ofarray[0]
(not penalized on the free response)going out of bounds when looping through an array (using
index <= array.length
). You will get anArrayIndexOutOfBoundsException
.jumping out an loop too early by using one or more return statements before every value has been processed.
You have attempted of activities on this page