Java Exception Handling (Try-catch)

  • + 0 comments

    import java.io.; import java.util.;

    public class Solution {

    public static void main(String[] args) {
            Scanner scan= new Scanner (System.in);
            try {
                   int a=scan.nextInt();
        int b=scan.nextInt();
        int c=a/b;
        System.out.println(c);
        }catch(InputMismatchException ie){
            System.out.println("java.util.InputMismatchException");
        }catch(ArithmeticException ae){
            System.out.println("java.lang.ArithmeticException: / by zero");
        }
    
    }
    

    }