MCQ Practice Single Best Answer Topic: ICSE Computer Application - Class X - 2022 PYQ

Q

What will be the output of the following code?

System.out.println("Lucknow".substring(0,4));

Question ID
#23972
Subchapter
ICSE Computer Application - Class X - 2022 PYQ
Action
Choose one option below

Choose Your Answer

Click an option to check whether your answer is correct.

  • A Lucknow
  • B Luckn
  • C Luck
  • D luck
Correct Answer: C

Explanation

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.

Share This Question

Share this MCQ with your friends or study group.