Single Choice Moderate

QGive output of the following String methods:

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

ID: #23965 ICSE Computer Application - Class X - 2022 PYQ 81 views
Question Info
#23965Q ID
ModerateDifficulty
ICSE Computer Application - Class X - 2022 PYQTopic

Choose the Best Option

Click any option to instantly check if you're correct.

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

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

Challenge a friend or share with your study group.