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 } }
2 odpowiedzi
+ 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.
0
yTTS
Thanks for the link👍