forked from SedaKunda/hackerrank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTryCatch.java
More file actions
31 lines (26 loc) · 897 Bytes
/
TryCatch.java
File metadata and controls
31 lines (26 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
This problem will test your knowledge on try-catch block.
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.
*/
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class TryCatch {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
try {
int y = in.nextInt();
int z = in.nextInt();
int r = y/z;
System.out.print(r);
}
catch (InputMismatchException e) {
System.out.print("java.util.InputMismatchException");
}
catch (Exception e) {
System.out.print(e);
}
}
}