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][count];
    
        for(int i = 0; i < list.length; i++)
        {
            copy[i][0] = list[i];
            
            for(int j = 0; j < count; j++)
            {
                System.out.print(copy[i][j] + "  ");
            }
        }
        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
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