Skip to content

Latest commit

 

History

History
29 lines (23 loc) · 784 Bytes

File metadata and controls

29 lines (23 loc) · 784 Bytes

Leniency

It can make sense to be lenient with your users when interpreting their input.1

This means accounting for common mistakes people make like having extra spaces or capitalizing things incorrectly.

For this purpose, methods like strip and equalsIgnoreCase are useful.

void main() {
    while (true) {
        String response = IO.readln("Answer me: yes or no").strip();
        if (response.equalsIgnoreCase("yes")) {
            IO.println("aight");
        }
        else if (response.equalsIgnoreCase("no")) {
            IO.println("cool");
        }
        else {
            IO.println("try again");
            continue;
        }

        break;
    }
}

Footnotes

  1. People are idiots. Their fingers are fat and their wills are weak.