-
Notifications
You must be signed in to change notification settings - Fork 0
/
day40.java
53 lines (37 loc) · 1.57 KB
/
day40.java
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
/*
Exception handling is the process of responding to the occurrence, during computation, of exceptions – anomalous or exceptional conditions requiring special processing – often changing the normal flow of program execution. (Wikipedia)
Java has built-in mechanism to handle exceptions. Using the try statement we can test a block of code for errors. The catch block contains the code that says what to do if exception occurs.
This problem will test your knowledge on try-catch block.
You will be given two integers and as input, you have to compute . If and are not bit signed integers or if is zero, exception will occur and you have to report it. Read sample Input/Output to know what to report in case of exceptions.
Sample Input 0:
10
3
Sample Output 0:
3
Solution -
*/
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
try{
Scanner sc = new Scanner(System.in);
int x=sc.nextInt();
int y=sc.nextInt();
int z=x/y;
System.out.println(z);
}
catch(InputMismatchException e)
{
System.out.println("java.util.InputMismatchException");
}
catch(ArithmeticException e)
{
System.out.println("java.lang.ArithmeticException: / by zero");
}
}
}