- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHandling_Exception.java
More file actions
Latest commit
32 lines (30 loc) · 1.1 KB
/
Copy pathHandling_Exception.java
File metadata and controls
32 lines (30 loc) · 1.1 KB
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
importjava.util.Scanner;
publicclassHandling_Exception {
publicstaticvoidmain(String[] args) {
int [] marks = newint[3];
marks[0] = 7;
marks[1] = 45;
marks[2] = 99;
Scannersc = newScanner(System.in);
System.out.println("Enter the array index");
intind = sc.nextInt();
System.out.println("Enter the number you want to divide the value with");
intnumber = 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 (ArithmeticExceptione){
System.out.println("ArithmeticException occured!");
System.out.println(e);
}
catch (ArrayIndexOutOfBoundsExceptione){
System.out.println("ArrayIndexOutOfBoundsException occured!");
System.out.println(e);
}
catch (Exceptione){
System.out.println("Some other exception occured!");
System.out.println(e);
}
}
}