-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexceptionarrayindex.java
More file actions
33 lines (31 loc) · 928 Bytes
/
exceptionarrayindex.java
File metadata and controls
33 lines (31 loc) · 928 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
package Lab;
import java.io.*;
import java.util.*;
public class exceptionarrayindex {
public static void main (String args[])
{
Scanner sc=new Scanner(System.in);
try
{
System.out.println("Enter the size of the array");
int s=sc.nextInt();
System.out.println("Enter the elements of the array ");
int arr[]=new int[s];
for(int i=0;i<s;i++)
arr[i]=sc.nextInt();
System.out.println("Enter the location to be accessed");
int l=sc.nextInt();
System.out.println(arr[l]);
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println(e);
}
catch(NegativeArraySizeException n)
{
System.out.println(n);
}
finally {
System.out.println("End of operation");
}
} }