我刚开始学习
Java.在我关注的在线课程中,我被要求尝试以下代码:
String email1 = "meme@me.coh";
String email2 = "meme@me.com";
Boolean isMatch = false;
isMatch = email1.equals (email2);
if (isMatch == true){
System.out.println("Emails match");
}
else{
System.out.println("Emails don't match");
}
我不明白为什么在下一行我被要求将isMatch声明为false我正在比较电子邮件地址并将值分配给isMatch.
我已经尝试了以下代码,它似乎工作原理相同:
String email1 = "meme@me.coh";
String email2 = "meme@me.com";
Boolean isMatch;
isMatch = email1.equals (email2);
if (isMatch == true){
System.out.println("Emails match");
}
else{
System.out.println("Emails don't match");
}
在课程中,它没有解释为什么我首先声明isMatch为false.在比较电子邮件地址之前,我有必要将isMatch声明为false吗?