[go: up one dir, main page]

0% found this document useful (0 votes)
13 views2 pages

Exception Handling(OOP-6)

Exceptional file handling

Uploaded by

darklover4545
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Exception Handling(OOP-6)

Exceptional file handling

Uploaded by

darklover4545
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.util.

Scanner; public
class Main{
public static void main (String []args){
Scanner sc =new Scanner(System.in);
try{
System.out.println("Enter first no.");
String input1 =sc.nextLine();
System.out.println("Enter second no.");
String input2 =sc.nextLine(); int num1=
Integer.parseInt(input1); int num2=
Integer.parseInt(input2);
int result=num1/num2;
System.out.println(num1+" / "+num2+" : "+result);
int arr[]={10,20,30};
System.out.println("enter the index of element to be found");
int key=sc.nextInt(); System.out.println(arr[key]);
}
catch(NumberFormatException e){
System.out.println("Error: Both no’s are not Valid Integers ");
}
catch(ArithmeticException e){
System.out.println("Error: Can’t divide no. by zero");
}
catch(ArrayIndexOutOfBoundsException e){
System.out.println("Error: Array index out of range");
}
finally{
System.out.println("Program executed Successfully ");
}
}
}
OUTPUT:
Enter first no :10
Enter second no :0
Error: Can’t divide no. by zero

Enter first no :10.5


Enter second no :11.2
Error: Both no’s are not Valid Integers

Enter first no :10 Enter second no:5


the division(10 / 5) : 2 enter the index of
element to be found 2 element found is
:30

Enter first no:10


Enter second no:5 the division(10 / 5): 2
enter the index of element to be found :3
Error: Array index out of range

Program executed Successfully

You might also like