Test multiple try-catch statement in java ex1

Write a program to test multiple try-catch statement in java.

package Exception_demo;

import java.util.*;
public class multiplecatch1
{
    public static void main(String args[])
    {
    Scanner s=new Scanner(System.in);
    try
    {
        String s1;
        System.out.println("enter string");
        s1=s.next();
        int j=Integer.parseInt(s1);
         int size;
        System.out.println("Enter size of array");
        size=s.nextInt();
        int a[]=new int[size];
        int i;
        System.out.println("enter the elements::");
            for(i=0;i<10;i++)
            {
                a[i]=s.nextInt();            
            }
            for(i=0;i<size;i++)
            {
                System.out.println("elements are::"+a[i]);
            }
        int p,q,r=0;
       // Scanner s=new Scanner(System.in);
        System.out.println("enter the value of p:");
        p=s.nextInt();
        System.out.println("enter the value of q:");
        q=s.nextInt();
        p=q/r;
        System.out.println("value of c is:"+p);
        System.out.println("bhavesh jain");
         String s2=null;
            System.out.println(s2.length());
    }
    catch(ArithmeticException e)
    {
        System.out.println(e);
    }
    catch(ArrayIndexOutOfBoundsException e)
    {
        System.out.println(e);
    }
    catch(NullPointerException e)
    {
        System.out.println(e);
    }
    catch(NumberFormatException e)
    {
        System.out.println(e);
    }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *