Menu
Question Index
...

What will be the output of the following program?

import java.util.*;
public class HappyNewYear {
    public static void main(String args[]) {
        List<String> words = new ArrayList<String>();
        words.add("Happy");
        words.add("New");
        words.add("Year");
        int count = 0;
        for (String word : words) {
            System.out.print(word + " ");
            switch (word) {
                case "Year" :
                    System.out.print(words.indexOf(word) + "0");
                    break;
                default :
                    count++;
            }
            count += word.length();
        }
        System.out.print(count);
    }
}


Happy New Year 2012
Happy New Year 2016
HappyNewYear2014
Happy New Year 2014
Compilation Error or Runtime Error

Doubts

Problems

Topic: Collection Framework In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App