I am using a while loop and an if loop to determine a response and action. For some odd reason it continues to ignore my if statements.
Boolean _exit = false;
while (_exit == false){
System.out.println("\nWould you like another meal?\tYes or No?");
String answer = scan.next().toLowerCase();
if (answer == "yes"){
System.out.println("Reached1");
_exit = true;
}
if (answer == "no"){
System.out.println("Reached1");
exit = _exit = true;
}
Could someone explain what is happening and why it is failing to check the if statements. I've tried scan.nextLine as well. This problem even persisted when I removed of the toLowerCase as it was brought to my attention that it can have an affect on string values, though I did try Locale.English.
Any suggestions?