Advertisement
Shailrshah

Try and Multiple Catches

Dec 18th, 2013
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.InputMismatchException;
  3. class Exceptions{
  4.         public static void main(String[] args){
  5.                 Scanner sc = new Scanner(System.in);
  6.                 System.out.println("Enter two numbers to perform division:-");
  7.                 try{
  8.                         int a = sc.nextInt();
  9.                         int b = sc.nextInt();
  10.                         System.out.println("The division is "+a/b);
  11.                 }catch(InputMismatchException e){
  12.                         System.out.println("The input should be an int.");
  13.                 }catch(ArithmeticException e){
  14.                         System.out.println("The second number must not be 0.");
  15.                 }catch(Exception e){
  16.                         System.out.println("Some error has occured.");
  17.                 }
  18.         }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement