/*
 * Code16.java
 * Dan Armendariz
 * Computer Science S-76
 *
 * Using a do-while loop to guarantee valid input from the user.
 *
 */

import java.util.Scanner;

class Code16 {

	public static void main(String [] args) {

		boolean invalid;
		int input = 0;

		// instantiate the Scanner class, accessing data from the keyboard
		Scanner keyboard = new Scanner(System.in);

		do {

			invalid = false;
			System.out.print("Please enter an integer: ");		

			// try inputting an integer, if a user doesn't ..
			try {
	
				input = keyboard.nextInt();
	
			} catch(Exception e) {
				// an exception will be thrown, and we can catch it to alert
				// the user that something bad happened.
	
				System.out.println("Invalid input! Please try again..");
				invalid = true;
				keyboard.next();
			}

		} while (invalid);

		System.out.println("You have finally entered a valid integer: "+input);

	}

}