Menu
Topics Index
...
`

Happy Vijaya Dasami


If you need explanation Read this topic

If you need Answer Take test on this topic

Happy Vijaya Dasami
What will be the output of the following program?
public class HappyVijayaDasami {

    public static void main(String[] args) {
        String[] greetings = {"Hoppy", "Vijoyo", "Dasami"};
        int i = 0;
        while (i < greetings.length) {
            print(i, greetings[i++]);
        }
    }

    private static void print(int i, String string) {
        switch (i) {
            default :
                string = string.replace('o', 'a');
            case 1 :
                string = new StringBuffer(string).reverse().toString();
                break;
            case 2 :
                string = string.toUpperCase();
                break;
        }
        System.out.print(string + " ");
    }
}

A. Happy Vijaya DASAMI
B. yppaH oyojiV DASAMI 
C. Happy oyojiV DASAMI 
D. Some other output or Compilation Error
Topic: Conclusion Of Strings 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:B First i=0 goes default case "Happy" then goes to case1 because there is no break statment "yppah". then break statemnt. "yppah". i=1 goes to case 1: "oyojiv" the case:2 "DASAmi"

Posted by Indrasena Reddy    2014-05-26 08:10:13


ans Di think we get an compilation error because of an input problemn by private or

Posted by Vinod Avulapati    2014-05-26 13:29:58


or else if didnt get an standard input problem because of private means if clear that then we get an answer as b

Posted by Vinod Avulapati    2014-05-26 13:30:53


ans : d
greeting is a array of string...
so in for loop its index should be given to indicate individual string
so code executed with error

Posted by Ananda Kumar    2014-05-26 14:04:13


Answer : B
> When i=0 in print() no case matchesdefault case is executed and as it has no break it executes Case 1 also  and prints "yppaH"
> When i=1 in print() case 1 is executed and it reverses the String oyojiv
>When i = 2 in print() case 2 is executed which prints  DASAMI as it changes everything toUpperCase()

Posted by Deepak Kumar Yadav    2014-05-26 15:38:31


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

Posted by Merit Campus    2014-05-28 14:52:15


© meritcampus 2019

All Rights Reserved.

Open In App