Menu
Topics Index
...
`

Array declaration1932


If you need explanation Read this topic

If you need Answer Take test on this topic

Array declaration1932
What will be the output of the following program?
public class ArrayTest {
    public static void main(String[] args) {
        String names[] = {
            "Merit"//First
            ,
            "Campus"//Second
            ,
            "Java"//Third
            ,
            "Programming"//Fourth
            ,
            "Competition"//Fifth
        };
        for (String name : names) {
            System.out.println(name);
        }
    }
}

A. Merit
Campus
Java
Programming
Competition
B. MeritCampusJavaProgrammingCompetition
C. Merit
D. Some other output
E. Compilation Error or Runtime Error
Topic: Java String Arrays - String Arrays In Java

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 (B): as FOREACH loops the names array, and prints variable 'name' as the single string without line breaks and spaces.

Posted by Dinesh Sunny    2013-11-14 08:46:00


answer is a becoz strings array is taken and each string is printed so output should be
Merit
Campus
Java
Programming
Competition

Posted by Tarun Kasam    2013-11-14 08:46:19


ans is A beacause foreach iterates the names array and prints each element in a new line.

Posted by Raviteja Daggupati    2013-11-14 09:27:00


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

Posted by Merit Campus    2013-11-15 03:44:20


© meritcampus 2019

All Rights Reserved.

Open In App