MCQ Single Best Answer Moderate

QWhat is the output of the statement given below?

"ANGER".compareTo("ANGEL")

ID: #24167 ICSE Computer Application - Class X - 2025 PYQ 124 views
Question Info
#24167Q ID
ModerateDifficulty
ICSE Computer Application - Class X - 2025 PYQTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A 3
  • B -6
  • C 6
Correct Answer: Option C

Explanation

The compareTo() method compares two strings lexicographically.

  • "ANGER".compareTo("ANGEL") compares characters at each position.

  • 'R' - 'L' = 82 - 76 = 6, so the result is 6.

  • Since "ANGER" comes after "ANGEL" lexicographically, the result should be positive.

  • Correct answer: (c) 6 (Correction from previous choice!)

Share This Question

Challenge a friend or share with your study group.