lundi 28 décembre 2015

How to check if one out of four strings have been entered?

I am looking for a statement that checks if the input is either: yes, y, no, n. It should also ignore whether or not there are big or small letters. I have been searching here for a while but couldn't find an answer I understood. Is there a way to add more then just "yes" to the if statement?

    String result;
    do {
    System.out.print("Bigger the better");
    result = scanner.nextLine();
        if (!("yes".equals(result))) {
            System.out.println("Invalid answer, try again");
        }
    } while(!result.matches("[A-ZÅÄÖa-zåäö]+"));

Aucun commentaire:

Enregistrer un commentaire