Menu
Topics Index
...
`

Print output by using Switch


If you need explanation Read this topic

If you need Answer Take test on this topic

Print output by using Switch
What will be the output of the following program?
public class KIs {
    public static void main(String args[]) {
        int k = 65;
        switch (k) {
            default :
                System.out.print("Website");
            case 65 :
                System.out.print("Merit");
            case 'k' :
                System.out.print("Campus");
            case 'j' :
                System.out.print("Java");
                break;
        }
    }
}

A. WebsiteMeritCampusJava
B. MeritCampusJavaWebsite
C. Merit
D. MeritWebsite
E. Some other output
F. Compilation Error or Runtime Error
Topic: switch Statement 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.

E) " some other output " the output will be '  MeritCampusJava ', here the word Website is to printed only for the default case i.e; when all the cases goes wrong.

Posted by Rockko Bhargava    2013-09-10 04:34:32


Ans is E
actual ans is MeritCampusJava
k matches with 65. Since there is no break, all the statements are executed till break is encountered.

Posted by Vallab Srinath    2013-09-10 04:35:56


E..bcoz..as it is switch d condition macthes with case 65 and "Merit" and there is no break ,so untill break comes..all case statements a followed and gets printed

Posted by Bhavya Rishitha    2013-09-10 04:36:44


the coreect option is A.since no break statement is available at each and every case evry case's statement is printed out to sceen .as default is placed 1st it prints the same without actually checking anything and other cases will be printed as there is no break statements

Posted by Veda Sree    2013-09-10 04:48:15


Answer is E,
MeritCampusJava.

Posted by Amar Kumar Biradar    2013-09-10 05:05:01


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

Posted by Merit Campus    2013-09-11 03:44:29


© meritcampus 2019

All Rights Reserved.

Open In App