What is the output of the statement given below?

ICSE Class 10 Computer Applications PYQ · 2025 Paper · Section A

1(xix)1 Mark · 2025 · Section A · 2025 Paper

What is the output of the statement given below?

"ANGER".compareTo("ANGEL")

Show SolutionHide Solution↓

6

Reason — The compareTo() method compares two strings lexicographically by comparing their characters one by one. It returns the difference between the first pair of characters that differ in the two strings.

Here, comparing "ANGER" and "ANGEL":

  • Characters 'A', 'N', 'G', and 'E' are the same in both strings at positions 0 to 3.
  • At position 4, 'R' (ASCII value 82) in "ANGER" is compared with 'L' (ASCII value 76) in "ANGEL".
  • The difference is 82 - 76 = 6.

Thus, the output is 6.

← Previous questionNext question →

Browse the free Computer Applications sample bank