We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent cd3d03b commit 4e568fbCopy full SHA for 4e568fb
1 file changed
Hackerrank/java_exception_handling(try-catch).java
@@ -0,0 +1,29 @@
1
+import java.io.*;
2
+import java.util.*;
3
+import java.text.*;
4
+import java.math.*;
5
+import java.util.regex.*;
6
+
7
+public class Solution {
8
9
+ public static void main(String[] args) {
10
11
12
+ Scanner scan = new Scanner(System.in);
13
+ try {
14
+ int x = scan.nextInt();
15
+ int y = scan.nextInt();
16
+ System.out.println(x / y);
17
+ }
18
+ catch(ArithmeticException | InputMismatchException e) {
19
+ if (e instanceof ArithmeticException) {
20
+ System.out.println("java.lang.ArithmeticException: / by zero");
21
+ } else if (e instanceof InputMismatchException){
22
+ System.out.println("java.util.InputMismatchException");
23
24
25
+ scan.close();
26
27
28
29
+}
0 commit comments