maygapixel

Untitled

Apr 28th, 2018
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2. import java.util.*;
  3. public class Exception1 {
  4.   public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.         int num = 0;
  7.     try{
  8.         do {
  9.               System.out.println("Enter a number between 1 and 10");    
  10.               num = scan.nextInt();
  11.               if (num < 1 || num > 10)            
  12.               System.out.println("\nIllegal value, " + num + " entered.  Please try again.");
  13.            }  while (num < 1 || num > 10);    
  14.               System.out.println("\nValue correctly entered! Thank you.");
  15.     }
  16.     catch (InputMismatchException ime) {
  17.         System.out.println("Enter whole numbers only, with no spaces or other characters");
  18.         scan.next();        // clear the scanner buffer
  19.     }
  20.   }
  21. }
Add Comment
Please, Sign In to add comment