Menu
Question Index
...

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 = j - i;

        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);
    }
}


Sum = 40
Sum = 30
Sum = 10
Compilation error
Throws ArrayIndexOutOfBoundsException

Doubts

Problems

Topic: Learn Arrays And Loops

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App