Advertisements
Advertisements
Question
Given:
int KH[] = {0, 0, 0, 0, 0, 0}
int len = KH.length;
system.out.print("array length="+len);
The output will be ______.
Options
array length = 6
array length = 0
array length = 7
array length = 5
MCQ
Fill in the Blanks
Advertisements
Solution
The output will be array length = 6.
Explanation:
- Counting Elements: The array variable
KHexplicitly contains six zero values enclosed within its curly brackets. - Length Property: The built-in
.lengthproperty in Java accurately counts the total number of allocated storage slots inside an array regardless of the values stored in them. - Final Print: The program prints out the text literal exactly as specified, displaying
array length=6on the console screens.
shaalaa.com
Is there an error in this question or solution?
Chapter 7: Arrays - One Dimension - Exercises [Page 173]
