package examples;

import java.util.Scanner;

public class ScannerPreventExceptions {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		System.out.print("Enter a long: ");
		
		while( ! sc.hasNextLong() ) {
			System.out.println("Oops, that's not a long.");
			System.out.println("Please try again...");
			// read in what they incorrectly entered
			sc.nextLine(); 
			System.out.print("Enter a long: ");
		}

		long myLong = sc.nextLong();
		
		System.out.println("You entered " + myLong);
		sc.close();
	}

}
