Skip to content

Commit e91160f

Browse files
Create Exceptional_Handling Divide 0.java
1 parent ab7d9a0 commit e91160f

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

Exceptional_Handling Divide 0.java

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
Prerna is playing game of number division with her friend , taking 2 input numbers both are of numeric type only. Prerna defines rules for game is like that if second number is zero then it will print A whereas A defines Arithmetic Exception and if second number is not zero then it simply print its result and that is also of numeric type.
3+
4+
Input Format
5+
6+
In first line , enter first number. In second line , enter second number
7+
8+
Constraints
9+
10+
both the input numbers must be integer
11+
12+
Output Format
13+
14+
Output depends upon second number, if it is 0 then it will print A which means Arithmetic Exception, but if second number is not zero then it will print result of division.
15+
16+
Sample Input 0
17+
18+
34
19+
0
20+
Sample Output 0
21+
22+
A
23+
*/
24+
import java.io.*;
25+
import java.util.*;
26+
27+
public class Solution {
28+
29+
public static void main(String[] args) {
30+
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
31+
Scanner sc = new Scanner(System.in);
32+
int a = sc.nextInt();
33+
int b = sc.nextInt();
34+
try{
35+
int result = a/b;
36+
System.out.print(result);
37+
}
38+
catch (Exception e)
39+
{
40+
System.out.print("A");
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)