+ 1
Please explain me, output of this code?
public class Program { public static void main(String[] args) { String s1="java"; String s2="java"; String s3="JAVA"; int i=s1.compareTo(s2); int j=s2.compareTo(s3); int k=s3.compareTo(s2); System.out.println(i); System.out.println(j); System.out.println(k); } } //output /* o 32 -32 */
2 ответов
+ 2
ASCII value of 'j': 106
ASCII value of 'J': 74
first output is 0 because s1 == s2.
second output is positive because s2 > s3.
third output is negative because s3 < s2.
You get 32 because the first different letters in s2 and s3 are 'j' and 'J', and the difference between them is 106-74 = 32.
also read this:
https://www.javatpoint.com/java-string-compareto
0
Thank You very much for tha answer.