import java.util.Scanner;
import java.util.InputMismatchException;
//=================================================================================================
public class ReadSafelyFinally {
//-------------------------------------------------------------------------------------------------
    private static final Scanner keyboard = new Scanner(System.in);
//-------------------------------------------------------------------------------------------------
    public static void main(String[] args) {

        System.out.println("The 1st value read is " + readAnInteger("Age of a buffalo"));
        System.out.println("The 2nd value read is " + readAnInteger("Age of a tiger"));
        System.out.println("The 3rd value read is " + readAnInteger("Age of a hippopotamus"));
    }
//-------------------------------------------------------------------------------------------------
    public static int readAnInteger(String prompt) {

        int intValue = 0;

        System.out.printf("%-20s: ",prompt);
        try {
            intValue = keyboard.nextInt();
            return(intValue);
        } catch (InputMismatchException e) {
            System.out.println("That is not an int");
            return(0);
        } finally {
            keyboard.nextLine();
            System.out.println("The final value is " + intValue);
        }
    }
//-------------------------------------------------------------------------------------------------
}
//=================================================================================================
