We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
importjava.util.Scanner;importjava.util.InputMismatchException;publicclassSolution{publicstaticvoidmain(String[]args){Scannerscan=newScanner(System.in);try{intx=scan.nextInt();inty=scan.nextInt();System.out.println(x/y);}catch(InputMismatchExceptione){System.out.println(e.getClass().getName());}catch(ArithmeticExceptione){System.out.println(e.getClass().getName()+": / by zero");}}}
Java Exception Handling (Try-catch)
You are viewing a single comment's thread. Return to all comments →
Java solution - passes 100% of test cases
From my HackerRank solutions.
Let me know if you have any questions.