Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package exceptions;
- import java.util.*;
- public class Exceptions {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int a,b,div;
- System.out.println("Input 2 numbers");
- a=sc.nextInt();
- b=sc.nextInt();
- try{
- div=a/b;
- System.out.println(div);
- }
- catch(ArithmeticException e){
- System.out.println("Exception Caught : Divide by Zero: "+e);
- }
- int arr[]={1,2,3,4,5};
- try{
- System.out.println("fifth element is " + arr[5]);
- }
- catch(ArrayIndexOutOfBoundsException e1){
- System.out.println("Out of Bounds :" + e1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment