45.5k views
4 votes
Given the declaration String[] names = new String[10] ; Which of the following statements puts a reference to the String "Hello" in the last cell of the array?

1 Answer

3 votes

Final answer:

To put a reference to the string "Hello" in the last cell of the array, you should use the statement names[9] = "Hello", as the last index of a 10-element array is 9.

Step-by-step explanation:

The student's question is about how to put a reference to the string "Hello" in the last cell of a string array in Java. Given the array declaration String[] names = new String[10], the last cell of the array is at index 9 because array indexing starts at 0. To assign the string "Hello" to the last cell, the correct statement would be names[9] = "Hello".

User Apinho
by
6.9k points