-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaTryCatch.java
More file actions
57 lines (37 loc) · 1.31 KB
/
JavaTryCatch.java
File metadata and controls
57 lines (37 loc) · 1.31 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.io.*;
import java.util.*;
class stringException extends Exception{
stringException(String str){}
}
class zeroException extends Exception{
zeroException(String str){}
}
public class JavaTryCatch {
public static void main(String[] args) throws IOException,Exception {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Scanner sc = new Scanner(System.in);
// while(sc.hasNext()){
try{
int x = sc.nextInt();
int y = sc.nextInt();
//to check if number is 0 hence division by zero exception must be raised.
if(y == 0){
throw new Exception("/ by zero");
}
else{
//else we print the division result
int result = x/y;
System.out.println(result);
}
}
catch(Exception e){
System.out.println(e);
}
}
}