Multiple choice

If str="foolishness", which expression returns "lish"?

  1. str.substring(3,7)

  2. str.substring(4,8)

  3. String.substring(str, 3, 7)

  4. str.substring(3,6)

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The substring method in Java takes a starting index that is inclusive and an ending index that is exclusive. To extract 'lish', we start at index 3 (the letter 'l') and end at index 7 (the letter 'n'), which is not included.