Menu
Question Index
...

What will be the output of the following program?

class ArrayOutput
{
    public static void main(String s[])
    {
        int list[] = new int[] {1, 8, 7, 4, 5, 6, 3};
        int count = 1;
        int copy[][] = new int[list.length][list.length];
    
        for(int i = 0; i < list.length; i++)
        {
            for(int j = 0; j < list.length; j++)
            {
                copy[i][j] = list[i];
                System.out.print(copy[i][i] + "  ");
            }
            System.out.println();
        }
    }
}


1 8 7 4 5 6 3
1 8 7 4 5 6 3
1 8 7 4 5 6 3
1 8 7 4 5 6 3
1 8 7 4 5 6 3
1 8 7 4 5 6 3
1 8 7 4 5 6 3
1 8 7 4 5 6 3
1 1 1 1 1 1 1
8 8 8 8 8 8 8
7 7 7 7 7 7 7
4 4 4 4 4 4 4
5 5 5 5 5 5 5
6 6 6 6 6 6 6
3 3 3 3 3 3 3
1 1 1 1 1 1 1
0 8 8 8 8 8 8
0 0 7 7 7 7 7
0 0 0 4 4 4 4
0 0 0 0 5 5 5
0 0 0 0 0 6 6
0 0 0 0 0 0 3
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