Computer Applications
A single dimensional array has 50 elements, which of the following is the correct statement to initialize the last element to 100.
- x[51]=100
- x[48]=100
- x[49]=100
- x[50]=100
Java Arrays
ICSE Sp 2025
20 Likes
Answer
x[49]=100
Reason — In Java, arrays use zero-based indexing, meaning the first element of the array is at index 0. For an array with n elements, the last element is at index n - 1.
Given a single-dimensional array with 50 elements, the indices range from 0 to 49. Thus, the correct index for the last element is 49.
Answered By
10 Likes
Related Questions
Consider the array given below:
char ch[] = {'A','E','I','O', 'U'};Write the output of the following statements:
System.out.println(ch[0]*2);:- 65
- 130
- 'A'
- 0
To execute a loop 10 times, which of the following is correct?
- for (int i=11;i<=30;i+=2)
- for (int i=11;i<=30;i+=3)
- for (int i=11;i<20;i++)
- for (int i=11;i<=21;i++)
Method prototype for the method compute which accepts two integer arguments and returns true/false.
- void compute (int a, int b)
- boolean compute (int a, int b)
- Boolean compute (int a,b)
- int compute (int a, int b)
The statement that brings the control back to the calling method is:
- break
- System.exit(0)
- continue
- return