-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathch_81_exceptions.java
33 lines (31 loc) · 1.11 KB
/
ch_81_exceptions.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
import java.util.Scanner;
public class ch_81_exceptions {
public static void main(String[] args) {
int [] marks = new int[3];
marks[0] = 7;
marks[1] = 56;
marks[2] = 6;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the array index");
int ind = sc.nextInt();
System.out.println("Enter the number you want to divide the value with");
int number = sc.nextInt();
try{
System.out.println("The value at array index entered is: " + marks[ind]);
System.out.println("The value of array-value/number is: " + marks[ind]/number);
}
catch (ArithmeticException e){
System.out.println("ArithmeticException occured!");
System.out.println(e);
}
catch (ArrayIndexOutOfBoundsException e){
System.out.println("ArrayIndexOutOfBoundsException occured!");
System.out.println(e);
}
catch (Exception e){
System.out.println("Some other exception occured!");
System.out.println(e);
}
sc.close();
}
}