info@meritcampus.com    +91-85006-22255
...
`

Array declaration creation
What will be the output of the following program?
`public class DemoOnLong {    public static void main(String[] args)     {        long[][] input = new long[3][];        input[0] = new long[2];        input[1] = new long[3];        input[2] = new long[5];        input[0][1] = 12L;        System.out.println(input[0][1]);    }}`

 A. 12 B. 12L C. -12 D. -12L E. Compilation Error or Runtime Error
Topic:

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

Ans is A..here we have the concept of the 2 dimensional array concept...in 2-D we have the rows and colos...

syntax: int a[][]=new int[4][4];

here two values specifies the size of  rows and cols...
in 2-D array each row represents the 1-d matrix...

Array is an collection of similar data elements which will store in the adjacent memory locations...arrays are fixed in the size and arrays stores homogenious elements...

here we create the 2-d with three rows..next we are creating the 1-d array for each row...with 2,3,5..here no need to be same size in cols...here we create the 3 rows...
next we are inserting the element at 0,1 location...here we specify L Bcz internally every non decimal num treat as Int so in order to specify to system treat this num as Long so we are specifying L...again we are printing the num so it will print 12

Posted by Uday Kumar    2014-12-05 12:12:00

Answer is A.....here a 2-d array is declared....1st dimension indicates the index of 1-d array....2nd dimension indicates number of elements corresponding to index of 1-d array....in this program,input[0][1] means 0th 1-d array and 2nd element(1st index) and 12L is the value assigned (L is just  a representation that value is tored as long)and that is printed through system.out.println

Posted by Shashanka Mogaliraju    2014-12-05 12:15:14

This dose is now closed and the winners are Uday Kumar,  for 'First Correct Comment', Uday Kumar, Shashanka Mogaliraju,  for 'Best Comment' and Uday Kumar for the 'Popular Comment'. The 'lucky liker' is Uday Kumar. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2014-12-06 02:58:27