I tried to apply a simple yes / no input with java.util.Scanner. My code looks like this :
Ask Public Boolean (String Quest) {String Ensv = Scan (Search + "(Y / N)"); Answ = answ.split ("") [1] .toLowerCase (); If (answ == "y") {back true; } If (answerw == "n") {return false;} // If there is no answer printOut ("Please enter 'y' or 'n'! Answer:" + answ + "!);) Return; Search);}
To minimize it: This ends with an infinite request for reply. The answer is never understood, I have not found any clue what I did .
You ==
to compare stars in Java (OK You can, but this is to compare their literal values. A is not the right way) You need to use equal ()
:
if ("y" .equals (answ)) {return true; } If ("n" .equals (answ)) {return false;}
Comments
Post a Comment