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
Your Answer
Choose the Best Option
Click any option to instantly check if you're correct.
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
Continue Practice
Share
Share This Question
Challenge a friend or share with your study group.
More from This Topic