Java Exception Handling (Try-catch)

  • + 2 comments

    perfect solution in java for passing all the test cases :

    public static void main(String[] args) { try{ Scanner s = new Scanner(System.in); System.out.println(s.nextInt()/s.nextInt()); }catch(ArithmeticException e) { System.out.println(e);

    }catch(InputMismatchException e)
        {
        System.out.println(e.getClass().getName());
    }
        catch(Exception e)
    {
        System.out.println(e.getClass());
    }
    }