Menu
Topics Index
...
`

Array Output758


If you need explanation Read this topic

If you need Answer Take test on this topic

Array Output758
What will be the output of the following program?
class ArrayOutput
{
    public static void main(String s[])
    {
        int a[] = {12, 15, 16, 17, 19, };

        for(int i = 0; i < 5; i += 1)
        {
            System.out.println(a[i]);
        }
    }
}

A. 12
15
16
17
19
B. 12
15
16
17
C. 12
16
19
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 a. array a is initialized with 5 elements.for loop is used to access array elements. sop print array elements.compiler ignores trailing commas,so it wrks fine without compilation error

Posted by Maheshwari Natarajan    2015-02-18 14:55:35


Ans is A (12 15 16 17 19)

Here the concept of array is used.

-- Array of integers is declared with name "a" and with 5 elements in it. After 5 elements comma is there.

--After that for loop is used while  Rus from 0 to 5 and prints each element using the counter I.so every element will get printed on new line as printn() method is used.

OUTPUT:
12
15
16
17
19

Posted by Mânïshå Mùlchåndânï    2015-02-18 20:02:19


This dose is now closed and the winners are Maheshwari Natarajan,  for 'First Correct Comment', Mânïshå Mùlchåndânï, Sai Ram,  for 'Best Comment' and Sai Ram for the 'Popular Comment'. The 'lucky liker' is Mânïshå Mùlchåndânï. 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    2015-02-19 04:16:15


© meritcampus 2019

All Rights Reserved.

Open In App