The correct answer is C. The code s.replace(s.indexOf("B"), s.indexOf("C"), "Q") would cause s to be "AQCD".
The replace method of the StringBuilder class replaces the characters in a substring of this sequence with characters in the specified String. The substring begins at the specified start index and extends to the character at index end - 1 or to the end of the sequence if no such character exists.
In this case, s.indexOf("B") returns 1, which is the start index of the substring to be replaced, and s.indexOf("C") returns 2, which is the end index of the substring to be replaced. So, the character at index 1 ("B") is replaced with "Q", resulting in "AQCD".
upvoted 1 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
dilleman
3 months, 2 weeks agoStavok
6 months ago