-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathException.java
More file actions
49 lines (41 loc) · 1.41 KB
/
Exception.java
File metadata and controls
49 lines (41 loc) · 1.41 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.util.Scanner;
public class Exception {
public static void main(String[] args) {
Scanner ab= new Scanner(System.in);
int arr[]=new int[5];
System.out.print("Enter a size of array :- ");
int n=ab.nextInt();
System.out.println("Enter a element of array :- ");
try{
for(int i=0;i<n;i++){
arr[i]=ab.nextInt();
}
System.out.println("Display a element of array :- ");
for(int i=0;i<n;i++)
{
System.out.print(arr[i]+" ");
}
}
catch(ArrayIndexOutOfBoundsException e){
System.out.println("ArrayIndexOutOfBoundsException .");
}
finally{
System.out.println("Always print because its in final .");
}
String a ="aditya";
try{
int m=Integer.parseInt(a);
System.out.println("Integer :- "+m);
}
catch(NumberFormatException e){
System.out.println("this is string but not a numerical string so its can't change in Integer .");
}
try{
System.out.println("element is :- "+arr[4]);
System.out.println("element2 is :- "+arr[10]);
}
catch(ArrayIndexOutOfBoundsException e){
System.out.println("out of index value ");
}
}
}