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.
publicclassSolution{publicstaticvoidmain(String[]args){Scannerscan=newScanner(System.in);try{intx=scan.nextInt();inty=scan.nextInt();System.out.println(x/y);}catch(ArithmeticException|InputMismatchExceptione){if(einstanceofArithmeticException){System.out.println("java.lang.ArithmeticException: / by zero");}elseif(einstanceofInputMismatchException){System.out.println("java.util.InputMismatchException");}}scan.close();}}
Java Exception Handling (Try-catch)
You are viewing a single comment's thread. Return to all comments →