// Keeps asking until the answer is a whole number.

void main() {
    boolean answered = false;

    while (!answered) {
        String answer = IO.readln("Enter a number: ");
        if (answer == null) {
            break;
        }

        try {
            int number = Integer.parseInt(answer.strip());
            IO.println("Thank you. You entered " + number + ".");
            answered = true;
        } catch (NumberFormatException e) {
            IO.println("That is not a whole number.");
        }
    }
}

// From Groundwork, chapter 5 (ch05-repetition), box 2.
// This example is from Groundwork, licensed CC BY-NC-SA 4.0.
// Run with: java ch05_02.java
