What is the output of this program?
class Array11
{
public static void main(String[] args)
{
int[] x=new int[5];
x[0]=10;
x[1]=20;
x[2]=30;
x[3]=40;
x[4]=50;
x[5]=60;
x[-1]=70;
for(int a:x)
System.out.println(a);
}
}
/*
Output:- Exception[ArrayIndexOutOfBoundsException]
Explanation:- If we are trying to access array elements with out of range index then we
will get Runtime Exception saying "ArrayIndexOutOfBoundsException".
*/
{
public static void main(String[] args)
{
int[] x=new int[5];
x[0]=10;
x[1]=20;
x[2]=30;
x[3]=40;
x[4]=50;
x[5]=60;
x[-1]=70;
for(int a:x)
System.out.println(a);
}
}
/*
Output:- Exception[ArrayIndexOutOfBoundsException]
Explanation:- If we are trying to access array elements with out of range index then we
will get Runtime Exception saying "ArrayIndexOutOfBoundsException".
*/
0 comments: