Computer Applications
The output of the statement "talent".compareTo("genius") is:
- 11
- –11
- 0
- 13
Answer
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.