-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.java
More file actions
50 lines (45 loc) · 1.31 KB
/
Copy patherror.java
File metadata and controls
50 lines (45 loc) · 1.31 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
50
/*class d{
static int div(int a,int b,int c){
return a+b/c;
}}*/
import java.util.Scanner;
public class error {
public static void main(String[] args) {
/* int a=23;
int b= 0;
try {
System.out.println("\n diviion is ="+a/b);
} catch (ArithmeticException e) {
System.out.println(e);
System.out.println("hfta");
}
try {
d rr= new d();
int j = rr.div(3,4,-1);
System.out.println("\n illegal is ="+j);
}
catch (IllegalArgumentException e) {
System.out.println(e);
System.out.println("hehee");
}
}*/
int a[]={1,2,3,4,5,6};
boolean flag = true;
while(flag==true){
try {
Scanner sc = new Scanner(System.in);
System.out.println("enter the array index");
int r = sc.nextInt();
if(r>=0 && r<=a.length){
System.out.println("array index is"+r+"in bound");
flag=false;
}
if(r<=0 || r>=a.length){
System.out.println("array index is"+r+"not in bound so retry");
}
}
catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Invalid input. Please enter a valid integer.");
}
}}
}