QUESTION IMAGE
Question
given the following declaration: string s = \apples and bananas are yummy.\;
evaluate the expression: s.substring(1, 3)
- \app\
- \appl\
- \apple\
- \pp\
- \ppl\
- \pple\
- \p\
- \pl\
- \ple\
- none of these
your answer should be the number (1 - 10) next to the correct value.
Step1: Identify string indices
In Java, substring(startIndex, endIndex) uses 0-based indexing. For s = "Apples and bananas are yummy.", index 0 = 'A', index 1 = 'p', index 2 = 'p', index 3 = 'l'.
Step2: Extract substring
The method returns characters from startIndex (inclusive) to endIndex (exclusive). So s.substring(1, 3) takes characters at index 1 and 2: 'p' and 'p'.
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
- "pp"