ICSE Class 10 Computer Applications
Question 13 of 30
Solved Sample Paper 1 — Question 13
Back to all questions 13
Question Question 1(xiii)
What is the value returned by function compareTo( ), if the invoking string is less than the string compared?
- zero
- value less than zero
- value greater than zero
- None of the above
value less than zero
Reason — The compareTo() method compares two strings lexicographically, and returns a value based on the following logic:
if string1 > string2 the result will be a positive integer, i.e., result > 0
if string1 < string2 the result will be a negative integer, i.e., result < 0
if string1 = string2 the result will be 0, i.e., result = 0