-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathExcepctionDemo.java
63 lines (43 loc) · 1.07 KB
/
ExcepctionDemo.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
54
55
56
57
58
59
60
61
62
63
import java.io.*;
class ArithmaticOperation{
int a;
int b;
float res;
int arr[];
ArithmaticOperation(int a, int b){
this.a = a;
this.b = b;
arr = new int[a];
}
void div(){
try{
res = a/b;
System.out.println("Result od Div = "+res);
for(int i =0; i<=a;i++){
arr[i]=i*2;
}
}
catch(Exception ae){
System.out.println("Second Number is zero, change it");
}
catch(ArrayIndexOutOfBoundsException ob){
System.out.println("You entered more values");
}
finally{
System.out.println("This line will always run");
}
}
}
class ExceptionDemo{
public static void main(String[] args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter Two Numberes");
String str = br.readLine();
int a = Integer.parseInt(str);
str = br.readLine();
int b = Integer.parseInt(str);
ArithmaticOperation ao = new ArithmaticOperation(a,b);
ao.div();
System.out.println("Rest of my code");
}
}