Skip to content

Commit 527550f

Browse files
committed
Test knowledge of Try Catch
1 parent cf6c3a5 commit 527550f

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Java/ExceptionHandling/TryCatch.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
This problem will test your knowledge on try-catch block.
3+
4+
You will be given two integers xx and yy as input, you have to compute x/y. If x and y are not 32 bit signed integers or if y is zero, exception will occur and you have to report it. Read sample Input/Output to know what to report in case of exceptions.
5+
*/
6+
7+
import java.io.*;
8+
import java.util.*;
9+
import java.text.*;
10+
import java.math.*;
11+
import java.util.regex.*;
12+
13+
public class TryCatch {
14+
15+
public static void main(String[] args) {
16+
Scanner in = new Scanner(System.in);
17+
try {
18+
int y = in.nextInt();
19+
int z = in.nextInt();
20+
int r = y/z;
21+
System.out.print(r);
22+
}
23+
catch (InputMismatchException e) {
24+
System.out.print("java.util.InputMismatchException");
25+
}
26+
catch (Exception e) {
27+
System.out.print(e);
28+
}
29+
30+
}
31+
}

0 commit comments

Comments
 (0)