Advertisements
Advertisements
Question
Given that:
String ab = "Aaron Bernstein";
String db = ab.substring(ab.lastIndexOf('e');
What will be the length of db?
Options
8
3
2
0
MCQ
Advertisements
Solution
3
Explanation:
The
lastIndexOf('e') method finds the last occurrence of the letter 'e' in "Aaron Bernstein", which is at index position 12. The substring(12) method then extracts everything from that index to the end of the string, resulting in the word "ein", which contains exactly three characters.shaalaa.com
Is there an error in this question or solution?
Chapter 10: String Handling - Exercises [Page 246]
