JAVA
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
// use of multiple catch statements
public class ExcDemo
{
public static void main(String[] args) {
int numer[] = {4, 8, 16, 32, 64, 128, 256, 512};
int denom[] = {2, 0, 4, 4, 0, 8};
for(int i=0; i<numer.length; i++) {
try {
System.out.println(numer[i] + " / "
+ denom [i] + " is " +
numer[i] / denom[i]);
}
catch (ArithmeticException exc) {
System.out.println("Can't divide by zero");
}
catch (ArrayIndexOutOfBoundsException exc) {
System.out.println("No matching element found");
}
}
}
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run