RodneyShag / HackerRank_solutions

317 efficient solutions to HackerRank problems
MIT License
2.7k stars 1.45k forks source link

used toString Method #49

Open mikhi-mh opened 1 year ago

mikhi-mh commented 1 year ago

Updated Solution.java We can use toString Method instead of our string
Just observe the print statements of catch...

try{
            int x = input.nextInt();
            int y = input.nextInt();
            System.out.println(x/y);
        }
        catch(InputMismatchException e){
            // System.out.println("java.util.InputMismatchException");
            System.out.println(e.getClass().getName());
        }
        catch(ArithmeticException e){
            // System.out.println("java.lang.ArithmeticException: / by zero");
            System.out.println(e.toString());
        }