-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexceptions.java
More file actions
38 lines (35 loc) · 936 Bytes
/
exceptions.java
File metadata and controls
38 lines (35 loc) · 936 Bytes
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
import java.util.Scanner;
class exception
{
public static void main(String args[])
{
Scanner sc = new Scanner (System.in);
System.out.print("\n\nEnter the values for the expression: \n\nx = a/(b-c)\nEnter: ");
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
System.out.print("\n\n(i) Arithmatic Exception\n----------------------------");
try
{
int x=a/(b-c);
System.out.print("ANSWER: "+(a/(b+c)));
}
catch(ArithmeticException e)
{
System.out.println("\nDivision by zero!!\n");
}
System.out.print("\n\n(ii) Array out of bounds Exception\n----------------------------");
int p[]={5,10};
System.out.print("\nEnter the index: ");
int q = sc.nextInt();
try
{
int y=p[q]/(q-p[1]);
System.out.print("ANSWER: "+y+"\n\n\n");
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("Array index error !!\n\n");
}
}
}