-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathException.java
More file actions
25 lines (22 loc) · 735 Bytes
/
Exception.java
File metadata and controls
25 lines (22 loc) · 735 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
//Program to check valid index number of an array till it will be a valid input
//package Exception;
import java.util.Scanner;
class Myexception extends Exception{
}
public class Exception_2 {
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
int arr[] = new int []{1,2,3,4,5,6,7};
while (true)
{
System.out.println("Enter the value of index ");
int index = sc.nextInt();
try {
System.out.println("correct index number and the index value is " + arr[index]);
break;
}catch(Exception e){
System.out.println("wrong index input");
}
}
}
}