ICSE Class 10 Computer Applications Question 3 of 10

Solved 2022 Semester 2 Question Paper ICSE Class 10 Computer Applications — Question 3

Back to all questions
3
Question

Question 1(iii)

Give output of the following String methods:

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

  1. 0
  2. 5
  3. 6
  4. -5
Answer

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