Give the output of the following string functions:

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

Single Choice
Views 71

Answer:

  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

Related Articles:

This section is dedicated exclusively to Questions & Answers. For an in-depth exploration of Java Programming Language, click the links and dive deeper into this subject.

Join Our telegram group to ask Questions

Click below button to join our groups.