✏️ Explanatory Question

Give the output of the following string functions:

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

👁 74 Views
📘 Detailed Answer
🟢 Easy
💡

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