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) “ACHIEVEMENT”.replace(‘E’,’A’)
(ii)”DEDICATE”.compareTo(“DEVOTE”)
Answer:
The outputs will be as follows
“ACHIEVEMENT”.replace(‘E’,’A’) will yield ACHIAVAMANT //All occurances of character ‘E’ will be replaced by character ‘A’
“DEDICATE”.compareTo(“DEVOTE”) will yield -18 //The string do not compare and the comparison fails at third character D. Since D is smaller than V the value will be negative. also the difference between ASCII of V(86) and D(68) which is 18 would be printed in its negative form.
C. Sir| Created: 25-Mar-2018 | Updated: 22-Mar-2026|ICSE2018