Menu
Topics Index
...
`

Array Output763


If you need explanation Read this topic

If you need Answer Take test on this topic

Array Output763
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();
    }
}

A. 1 8 7 4 5 6 3
B. 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
C. 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
D. Compilation Error
E. Throws ArrayIndexOutOfBoundsException
Topic: Learn Arrays And Loops

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Ans is A.. copy is 7-1 matrix assigning list values  to copy and printing here..

Posted by Om Prakash Om    2014-03-10 03:46:28


Ans is A new list array takes 1,8,7,4,5,6,3 and values copied into copy 2d array values and int the loop the values are printed

Posted by Bharath Yelchuri    2014-03-10 13:07:23


Congratulations Om Prakash Om. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-03-11 04:26:10


© meritcampus 2019

All Rights Reserved.

Open In App