Give output of the following String methods:

ICSE Class 10 Computer Applications PYQ · 2022 Semester 2 · Section A

1(iii)1 Mark · 2022 · Section A · 2022 Semester 2

Give output of the following String methods:

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

Show SolutionHide Solution↓

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

← Previous questionNext question →

Browse the free Computer Applications sample bank