if statement - Java While Loops Issue -
this question has answer here:
- how compare strings in java? 23 answers
i using while loop , if loop determine response , action. odd reason continues ignore if statements.
boolean _exit = false; while (_exit == false){ system.out.println("\nwould 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 explain happening , why failing check if statements. i've tried scan.nextline well. problem persisted when removed of tolowercase brought attention can have affect on string values, though did try locale.english.
any suggestions?
compare strings .equals() not == in if statements:
if (answer.equals("yes")){ system.out.println("reached1"); _exit = true; } if (answer.equals("no")){ system.out.println("reached1"); exit = _exit = true; }
Comments
Post a Comment