Nested try catch ....
package com.company;
import java.util.Scanner;
public class CWH_82_nested_tryCatch {
public static void main(String[] args) {
// Scanner sc= new Scanner(System.in);
// System.out.println("Enter the number");
// int a= sc.nextInt();
// int b=45,c;
// try{
// System.out.println("Welcome to java tutorial !!");
// try {
// c=b/a;
// System.out.println(c);
// }
// catch(ArithmeticException e){
// System.out.println("Exception is: " +e);
// }
// }
// catch(Exception e){
// System.out.println(e);
// }
//Quiz
int [] num={2,3,4,5,6,7,8,9,10,11,12,13,56,78,90,100};
System.out.println(num.length);
boolean b=true;
while(b) {
Scanner arr = new Scanner(System.in);
System.out.println("Enter the value of index");
int i = arr.nextInt();
try {
System.out.println("The value of array at index " + i + " is " + num[i]);
b=false;
}
catch (IndexOutOfBoundsException e) {
System.out.println("Exception is " + e);
}
catch (Exception e) {
System.out.println("Exception is " + e);
}
}
System.out.println("Thanku for using my application");
}
}
Comments
Post a Comment