Create a free account on Computer Sir Ki Class and unlock access to valuable learning resources.
Exam Paper Downloads: After registering and logging in, you can download exam question papers in PDF format to practice and prepare for your exams.
Student Support: Get assistance with your doubts, queries, and questions related to your studies. Our support is here to help you understand topics and resolve your learning difficulties.
Register today and make your exam preparation easier and more effective!
Give the output of the following string functions :
(i) “MISSISSIPPI”.indexOf(‘S’) + “MISSISSIPPI”.lastIndexOf(‘I’)
(ii) “CABLE”.compareTo(“CADET”)
Answer:
(i) “MISSISSIPPI”.indexOf(‘S’) + “MISSISSIPPI”.lastIndexOf(‘I’)
“MISSISSIPPI”.indexOf(‘S’) would be 2 (first index where ‘S’ is found)
“MISSISSIPPI”.lastIndexOf(‘I’) = 10 (last index where ‘I’ is found)
Summing both would give 12
(ii) “CABLE”.compareTo(“CADET”)
Here the mismatch would occur at index 2 as B is different from D. Now since first string’s mismatched character is smaller so answer would be negative. To get the answer we will subtract ascii of B from ascii of D which would be (66-68) . So the answer would be -2 .
C. Sir| Created: 31-Mar-2018 | Updated: 22-Mar-2026|ICSE2016