I have just started learning Java. In the online course I am following, I am asked to try the following code:
String email1 = "[email protected]";
String email2 = "[email protected]";
Boolean isMatch = false;
isMatch = email1.equals (email2);
if (isMatch == true){
System.out.println("Emails match");
}
else{
System.out.println("Emails don't match");
}
I don't understand why I'm asked to declare isMatch as false when on the next line i am comparing the email addresses and assigning the value to isMatch.
I've tried the following code which seems to work just the same:
String email1 = "[email protected]";
String email2 = "[email protected]";
Boolean isMatch;
isMatch = email1.equals (email2);
if (isMatch == true){
System.out.println("Emails match");
}
else{
System.out.println("Emails don't match");
}
On the course it doesn't explain why I'm declaring isMatch as false first. Is there a reason why I must declare isMatch as false before comparing the email addresses?