Menu
Question Index
...

What will be the output of the following program?

class ArrayOutput
{
    public static void main(String aRGS[])
    {
        int[][] scores = new int[3][];
        scores[0] = new int[3];
        scores[1] = new int[4];
        scores[2] = new int[3];
        
        for(int i = 0; i < scores.length; i++)
        {
            for(int j = 0; j < scores.length; j++)
            {
                scores[i][j] = i + j;
                System.out.print(scores[i][j] + " ");
            }
        }
    }
}


0 1 2 1 2 3 4 2 3 4
0 1 2 4 7 11 16 22 30 37
0 1 2 1 2 3 2 3 4
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