Menu
Topics Index
...
`

Array Accessing


If you need explanation Read this topic

If you need Answer Take test on this topic

Array Accessing
What will be the output of the following program?
class ArrayOutput
{
    public static void main(String s[])
    {
        int a[] = new int[50];

        int i = 27 % 11;
        int j = 5 * 3;
        int k = i - j;

        a[i] = i;
        a[j] = j;
        a[k] = k;

        int sum = 0;

        for(int l = 0; l < a.length; l++)
        {
            sum += a[l];
        }

        System.out.println("Sum = " + sum);
    }
}

A. Sum = 40
B. Sum = 30
C. Sum = 10
D. Compilation error
E. Throws ArrayIndexOutOfBoundsException 
Topic: Learn Arrays And Loops

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Ans is E....
because 'k' value is -10
i=5,j=15,k=i-j=-10.
It throws AIOOBE.

Posted by Gopinath Manchikanti    2014-08-01 11:05:45


I think the 'E' is correct answer.

Posted by Necheer Nls    2014-08-01 11:07:48


ans is E

Posted by Shubham Bansal    2014-08-01 11:12:30


e

Posted by Zeg Abder    2014-08-01 12:52:22


answer is E. Thise reson is index is firt element 0.but lenth-1 is currect. becouse thise is ArrayIndexOutOfBoundsException.

Posted by Pothuluri Venkateswarlu    2014-08-01 13:40:50


e...........

Posted by Arul Palanisamy    2014-08-02 04:23:17


Congratulations Gopinath Manchikanti. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-08-04 06:02:54


© meritcampus 2019

All Rights Reserved.

Open In App