+ 3
why the output is like this?
public class rev { public static void main (String[] args){ String s1 = "hello"; String s2 = "hel" + "lo"; String s3 = " mum"; if(s1==s2){ System.out.println("1.same"); }else{ System.out.println("1.different"); } if(s1 + s3 == "hello mum"){ System.out.println("2.same"); } else{ System.out.print("2.different"); } } } #output: 1.same 2.different
2 ответов
+ 1
For comparing Strings, you should use .equals instead of ==.