+ 1
What did I miss?
public class StringCompare{ public static void main(String []args){ String s1 = "hey!"; String s2 = "hello"; if (s1 == s2){ System.out.println("The two texts are same"); } else { System.out.println("Nope! They are different"); } } }
3 Answers
+ 10
Don't use == to compare strings, use equals() method instead.
== returns true only if the two strings are same object (must occupy same memory address).
Code: https://code.sololearn.com/cA7blCcjcnE3/#java
+ 1
Turns out I missed a curly brace at the end(in the compiler- corrected here). Are there any modifications I can make to this simple code?
Can somebody show me how I can take user-provided values for s1 and s2?
Thanks!
+ 1
Thanks!!