Menu
Question Index
...

What will be the output of the following program?

public class DoubleStand
{
    public static void main(String avs[])
    {
        int[][] print = haiArray(4);
        for (int[] element : print)
        {
            for (int l = 0; l < element.length; l++)
            {
                System.out.print(l + " ");
            }
            System.out.println();
        }
    }
    static int[][] haiArray(int size)
    {
        int[][] printArray = new int[size][];
        int val = 1;
        for (int i = 0; i < printArray.length; i++)
        {
            printArray[i] = new int[i + 1];
            for (int j = 0; j < printArray[i].length; j++)
            {
                printArray[i][j] = val++;
            }
        }
        return printArray;
    }
}


0
0 1
0 1 2
0 1 2 3
0
1 2
3 4 5
6 7 8 9
1
1 2
1 2 3
1 2 3 4
1
2 3
4 5 6
7 8 9 10
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java Multidimensional Array

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App