# Could someone explain how to solve to this problem?

kenny gill

Ranch Hand

Posts: 54

kenny gill

Ranch Hand

Posts: 54

posted 4 years ago

Java arrays start at index 0, so in your example A[0] == 1

A.length returns the true length, in this case 4, so you must subtract 1 to get the last entry.

TIP: Be careful if length == 0, since you will then try to index A[-1] which will fail.

WP

A.length returns the true length, in this case 4, so you must subtract 1 to get the last entry.

TIP: Be careful if length == 0, since you will then try to index A[-1] which will fail.

WP

posted 4 years ago

To learn what exactly arrays are and how they work, see Arrays in Oracle's Java Tutorials.