The output of the statement "talent".compareTo("genius") is:

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

1(v)1 Mark · 2024 · Section A · 2024 Paper

The output of the statement "talent".compareTo("genius") is:

Show SolutionHide Solution↓

13

Reason — The method compareTo(String str) in Java compares two strings lexicographically based on the ASCII values of characters. It returns:

0 if both strings are equal.
A positive value if the calling string comes after the argument string.
A negative value if the calling string comes before the argument string.

How It Works:
We compare "talent" and "genius" using their first differing characters:

  • The ASCII value of 't' = 116
  • The ASCII value of 'g' = 103

The difference is:
116 - 103 = 13

Since 't' comes after 'g', the result is 13.

← Previous questionNext question →

Browse the free Computer Applications sample bank