ICSE Class 10 Computer Applications
Question 14 of 30
Solved Sample Paper 3 — Question 14
Back to all questions 14
Question Question 1(xiv)
What will be the output of the following code?
System.out.println("Lucknow".substring (0, 4));- Lucknow
- Luckn
- Luck
- luck
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.