Menu
Question Index
...

What will be the output of the following program?

public class Stand {
    public static void main(String avs[]) {
        haiArray(4);
    }
    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++;
                System.out.print(printArray[i][j] + " ");
            }
            System.out.println();
        }
        return printArray;
    }
}


1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
1 2 3 4
5 6 7
8 9
10
1
2 3
4 5 6
7 8 9 10
1 2 3 4
Compilation Error or Runtime Error

Doubts

Problems

Topic: Static and Non Static Variables - Static and Non Static Methods

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App