Computer Applications
What will be the output of the following code?
System.out.println("Lucknow".substring (0, 4));
- Lucknow
- Luckn
- Luck
- luck
Java String Handling
8 Likes
Answer
Luck
Reason — The substring() method returns a substring beginning from the startindex and extending to the character at index endIndex - 1. Since a string index begins at 0, the character at startindex (0) is 'L' and the character at the endIndex (4-1 = 3) is 'k'. Thus, "Luck" is extracted and printed on the screen.
Answered By
4 Likes
Related Questions
A binary search
- can be used with sorted arrays only.
- can be used with unsorted arrays only.
- can be used with both sorted and unsorted arrays.
- cannot be used with arrays.
Corresponding wrapper class of float data type is
- FLOAT
- float
- Float
- Floating
This access specifier is the most open access level.
- Public
- Protected
- Private
- Default
The method to determine whether the specified char value is in uppercase or not.
- toUpperCase(char)
- toLowerCase(char)
- isLowerCase(char)
- isUpperCase(char)