English

Given that: String ab = "Aaron Bernstein"; String db = ab.substring(ab.lastIndexOf('e'); What will be the length of db?

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]

APPEARS IN

Rupa Pandit Computer Applications [English] Class 10 ICSE
Chapter 10 String Handling
Exercises | Q 1. (ix) | Page 246
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×