exam questions

Exam 1z0-819 All Questions

View all questions & answers for the 1z0-819 exam

Exam 1z0-819 topic 1 question 107 discussion

Actual exam question from Oracle's 1z0-819
Question #: 107
Topic #: 1
[All 1z0-819 Questions]

Given the code fragment:



Which would cause s to be AQCD?

  • A. s.replace(s.indexOf("B"), s.indexOf("B"), "Q");
  • B. s.replace(s.indexOf("A"), s.indexOf("B"), "Q");
  • C. s.replace(s.indexOf("B"), s.indexOf("C"), "Q");
  • D. s.replace(s.indexOf("A"), s.indexOf("C"), "Q");
Show Suggested Answer Hide Answer
Suggested Answer: C 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
dilleman
3 months, 2 weeks ago
Selected Answer: C
Tested, C
upvoted 1 times
...
Stavok
6 months ago
Selected Answer: C
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
...
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.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago