Computer Applications

The index(subscript) of the last element of an array ar[] is:

  1. ar.length()
  2. ar[].length
  3. ar.length() – 1
  4. ar.length – 1

Java Arrays

8 Likes

Answer

ar.length – 1

Reason — In Java, the length of an array ar is given by ar.length (without parentheses). Since array indexing starts from 0, the last element's index is always one less than the total length of the array. Therefore, the index of the last element is ar.length – 1.

Answered By

4 Likes


Related Questions