12th Oct 2022, 1:54 PM
Ayush Singh
Ayush Singh - avatar
3 Respuestas
+ 2
You can have multiple catch for single try block ; try { divident = sc.nextInt(); divisor = sc.nextInt(); int result = divident/divisor; System.out.println("Result: " + result); } catch(java.util.InputMismatchException e) { System.out.println("Input integer."); } catch(ArithmeticException e) { System.out.println("Input non-zero Integer."); }
12th Oct 2022, 2:01 PM
Jayakrishna 🇮🇳
+ 3
Scanner sc = new Scanner(System.in); int divident, divisor, result; try{ divident = sc.nextInt(); divisor = sc.nextInt(); result = divident/divisor; System.out.println("Result: " + result); } catch(java.util.InputMismatchException e){ System.out.println("Input integer."); } catch(ArithmeticException e){ System.out.println("Input non-zero Integer."); }
12th Oct 2022, 2:00 PM
SoloProg
SoloProg - avatar
+ 2
SoloProg Jayakrishna🇮🇳 Thanks to both of you.
12th Oct 2022, 2:07 PM
Ayush Singh
Ayush Singh - avatar