Menu
Question Index
...

What will be the output of the following program?

public class LengthOfArray {
    public static void main(String[] args) {
        int[][][] x = new int[3 * 1][][];
        int i, j;
        int size = 0;
        x[0] = new int[3 * 2][];
        x[1] = new int[1 * 2][];
        x[2] = new int[2 * 2][];
        for (i = 0; i < x.length; i++) {
            for (j = 0; j < x[i].length; j++) {
                x[i][j] = new int[i + j + 1];
                size += x[i][j].length;
            }
        }
        System.out.println("Size = " + size);
    }
}


Size = 6
Size = 12
Size = 38
Size = 44
Compilation Error or Runtime Error

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