-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHandle_Specific_Exception.java
More file actions
35 lines (30 loc) · 1.05 KB
/
Handle_Specific_Exception.java
File metadata and controls
35 lines (30 loc) · 1.05 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
33
34
35
package com.company;
import java.util.Scanner;
public class Handle_Specific_Exception {
public static void main(String[] args) {
int[] marks={21,32,43,54};
Scanner sc=new Scanner(System.in);
System.out.println("Enter Your index : ");
int ind=sc.nextInt();
System.out.println("Enter the number you want to divide with the value ");
int num=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]/num);
}
catch (ArithmeticException e)
{
System.out.println("ArithmeticException Occurred");
System.out.println(e);
}
catch (ArrayIndexOutOfBoundsException e)
{
System.out.println("ArrayIndexOutOfBoundsException Occurred");
System.out.println(e);
}
catch (Exception e)
{
System.out.println(e);
}
}
}