Question 281
String s = "programming";
System.out.println(s.substring(3, 7) + "-" + s.indexOf("m"));
What is printed when the code segment executes?Main Solution
Answer
Answer: D. Indices: p=0, r=1, o=2, g=3, r=4, a=5, m=6, m=7, i=8, n=9, g=10. substring(3, 7) = "gram". indexOf("m") returns the first occurrence: index 6 (not 7).
Answer: Correct: D
Answer images

