Home / Questions / Give the output of the following string functions: "ACHIEVEMENT".replace('E', 'A') "DEDICATE".compareTo("DEVOTE")
Explanatory Question

Give the output of the following string functions:

  1. "ACHIEVEMENT".replace('E', 'A')
  2. "DEDICATE".compareTo("DEVOTE")

👁 74 Views
📘 Detailed Answer
🕒 Easy to Read
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.

Answer with Explanation

  1. ACHIAVAMANT
  2. -18
  1. "ACHIEVEMENT".replace('E', 'A') will replace all the E's in ACHIEVEMENT with A's.
  2. The first letters that are different in DEDICATE and DEVOTE are D and V respectively. So the output will be:
        ASCII code of D - ASCII code of V
    ⇒ 68 - 86
    ⇒ -18