HackerRank_solutions icon indicating copy to clipboard operation
HackerRank_solutions copied to clipboard

used toString Method

Open mikhi-mh opened this issue 1 year ago • 0 comments

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());
        }

mikhi-mh avatar May 21 '23 19:05 mikhi-mh