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?

  1. zero
  2. value less than zero
  3. value greater than zero
  4. None of the above
Answer

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