am having trouble trying to validate a user response to exit my app or try again(its a simple game)? when the game finishes I ask the user if they want to continue type "y" for yes or "n" for no to exit. How can I validate their response so if its neither y or n I show an error message and ask them to type it again???
This doesn't seem to worK for me???
if (!choice.equalsIgnoreCase("n") && !choice.equalsIgnoreCase("y"))
System.out.println("Error enter y for yes and n for no");
System.out.println("Would you like to play again (y/n):");
choice = sc.next();