Generate ArrayIndexOutOfBounds exception in java

Write a program to generate ArrayIndexOutOfBounds exception in java.

package Exception_demo;

import java.util.*;
public class exception_4
{
    public static void main(String args[])
    {
        Scanner s=new Scanner(System.in);
        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]);
            }
    }    
}

Leave a Reply

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