We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d009e41 commit db41af1Copy full SHA for db41af1
1 file changed
exceptionHandling/MyException.java
@@ -0,0 +1,25 @@
1
+import java.util.Scanner;
2
+class MyException
3
+{
4
+ public static void main(String args[])
5
+ {
6
+ try
7
8
+ Scanner sc = new Scanner(System.in);
9
+ System.out.println("Enter the size of the array");
10
+ int size = Integer.parseInt(sc.next());
11
+ int[] arr = new int[size];
12
+ for(int i=0;i<arr.length;i++)
13
14
+ arr[i]=Integer.parseInt(sc.next());
15
+ }
16
+ System.out.println("Enter a index no. Index starts from zero");
17
+ int index = Integer.parseInt(sc.next());
18
+ System.out.println(arr[index]);
19
20
+ catch(ArrayIndexOutOfBoundsException | NumberFormatException e)
21
22
+ System.out.println(e.getClass().getName());
23
24
25
+}
0 commit comments