Menu
Question Index
...

What will be the output of the following program.

class CalculateSum
{
    public static void main(String[] args)
    {
        int a[][] = {{1, 3, 4}, {2, 3}, {7, 6, 5, 4, 3, 2, 1}, {9}, {8}};
        int sum = 0;
        for(int i = 0; i < a.length; i++)
        {
            for(int j = 0; j < a[0].length; j++)
            {
                sum += a[i][j];
            }
        }
        System.out.println("sum = " + sum);
    }
}


sum = 58
sum = 8
sum = 73
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