Multiple choice

What would be the value of i after the execution of the following statements in Java? int i; String st1=”Rakesh”; String st2=”Roshan”; i=st1.compareTo(st2);

  1. 0

  2. 1

  3. -1

  4. +1

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Here, the output will be -1 because the ASCII difference of unmatched characters in “Rakesh” and “Roshan” is negative.