I am writing a simple program in java for command line. I would like to know how to be able to prompt the user if they are sure they would like to exit. Then based on the choice take appropriate action. It would be able to tell if they typed “Yes”, “yes”, “Y”, “y” or “No”, “no”, “N”, “n” or whatever. So far I have
System.out.println("Are you sure you want to quit? Yes/No");
String quitResponse;
quitResponse = input.next();
if("Yes".equals(quitResponse) || "Y" || "yes" || "y"){
System.exit(0);
I know the || is incorrect but I’m used to it in python.
This is just to give you an idea.
if("Yes".equalsIgnoreCase(quitResponse) || "Y".equalsIgnoreCase(quitResponse))