0

How does this code work? How to know what non zero output it gives?

public class Program { public static void main(String[] args) { String a = "hi"; String b = "hi"; int x = a.compareTo(b); System.out.println(x); // returns a 0 value if both strings are the same else give non zero input } }

19th Jul 2018, 11:15 AM
Parth Salat
Parth Salat - avatar
2 ответов
+ 1
Hello! Method compareTo returns 0 because your strings are equal. Learn more here: https://beginnersbook.com/2013/12/java-string-compareto-method-example/ Hope it will help you.
19th Jul 2018, 11:25 AM
dev.Y
dev.Y - avatar
0
yTTS Thanks for the link👍
19th Jul 2018, 11:33 AM
Parth Salat
Parth Salat - avatar