Asked by Alyssa Currie on Jun 18, 2024

verifed

Verified

String sentence;
String str1, str2, str3, str4;
Int length1;sentence = "First exam is on Monday.";str1 = sentence.substring(6, 12) ;
Str2 = str1.substring(0, 4) ;
Str3 = sentence.replace('i', '#') ;
Str4 = sentence.indexOf("on") ;length1 = sentence.length() ;Based on the code above, what is the value of str4?

A) 11
B) 12
C) 13
D) 14

Sentence.indexOf()

A method in Java that returns the index within the string of the first occurrence of the specified character or substring.

  • Recognize and apply the methods for string manipulation in Java proficiently.
verifed

Verified Answer

ML
Minous LulousJun 23, 2024
Final Answer :
D
Explanation :
The value of str4 is 14 because the indexOf method returns the index of the first occurrence of the specified substring, "on", which starts at the 14th position in the string "First exam is on Monday.".