Computer Applications
A single dimensional array contains 37 elements. Which of the following represents the index of its second-to-last element.
Java Arrays
1 Like
Answer
35
Reason — In Java, arrays use zero-based indexing. For an array with 37 elements, the indices range from 0
to 36
:
- The last element is at index
36
. - The second-to-last element is at index
35
(36 - 1
).
Answered By
1 Like
Related Questions
Define a class to search for a value input by the user from the list of values given below. If it is found display the message "Search successful", otherwise display the message "Search element not found" using Binary search technique.
5.6, 11.5, 20.8, 35.4, 43.1, 52.4, 66.6, 78.9, 80.0, 95.5.
Consider the following program segment and answer the questions given below:
int x[][] = {{2,4,5,6}, {5,7,8,1}, {34, 1, 10, 9}};
(a) What is the position of 34?
(b) What is the result of x[2][3] + x[1][2]?
What is the output of the Java code given below?
String color[] = {"Blue", "Red", "Violet"}; System.out.println(color[2].length());
- 6
- 5
- 3
- 2
Which of the following is a valid way to declare and initialize an integer array to store the ages of 50 students?