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

Q Give output of the following String methods:

"SUCESS".indexOf('S') + "SUCCESS".lastIndexOf('S')

Question ID
#23965
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.

  • B 5
  • C 6
  • D -5
Correct Answer: C

Explanation

6

Reason — indexOf() returns the index of the first occurrence of the specified character within the string and lastIndexOf() returns the index of the last occurrence of the specified character within the string. Since a string begins with index 0, the given methods are evaluated as follows:

"SUCESS".indexOf('S') + "SUCCESS".lastIndexOf('S')
⇒ 0 + 6
⇒ 6

Share This Question

Share this MCQ with your friends or study group.