Asked by Faith Fanning on Jun 14, 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 str3?

A) "First exam is on Monday."
B) "F#rst exam #s on Monday."
C) "F#rst exam is on Monday."
D) "#i### #### i###########."

Sentence.replace()

A method in programming languages like Java that replaces part of a string with another string.

  • Discover and utilize methods for altering strings in Java with efficacy.
verifed

Verified Answer

AS
Ashini SisaraniJun 21, 2024
Final Answer :
B
Explanation :
Str3 is obtained by replacing all occurrences of 'i' in the original sentence with '#', resulting in "F#rst exam #s on Monday.".