//    File:  ScanConsoleApp - Demonstrate use of the Scanner Class

//    Based on an original from "Java Tech"

import java.io.*;
import java.util.*;

/** Demonstrate the Scanner class for input of numbers.**/
public class ScanConsoleApp {

    public static void main(String[] arg) {

        // Create a scanner to read from the keyboard
        Scanner scanner = new Scanner(System.in);
        System.out.println("\nDemonstrate Use of the Scanner Class\n\n");

        try {
            System.out.printf("Input int (e.g. %4d): ", 3501);
            int intVal = scanner.nextInt();
            System.out.println("You entered " + intVal +"\n");

            System.out.printf("Input float (e.g. %5.2f): ", 2.43);
            float floatVal = scanner.nextFloat();
            System.out.println("You entered " + floatVal + "\n");

            System.out.printf("Input double (e.g. %6.3e): ", 4.943e15);
            double doubleVal = scanner.nextDouble();
            System.out.println("You entered " + doubleVal + "\n");

        } catch (InputMismatchException e) {
            System.out.println("Mismatch exception: " + e);
        }
    }

}
