Menu
Topics Index
...
`

Switch Output final


If you need explanation Read this topic If you need explanation Read this topic

If you need Answer Take test on this topic

Switch Output final
What will be the output of the program?
class Output
{
    final static short i = 2;
    public static int j = 0;
    
    public static void main(String [] args)
    {
        for (int k = 0; k < 3; k++)
        {
            switch (k)
            {
                case i: System.out.print(" 0 ");
                case i-1: System.out.print(" 1 ");
                case i-2: System.out.print(" 2 ");
            }
        }
    }
}

A. 2 1 0 1 0 0
B. 0 1 2 1 2 2
C. 2 1 2 0 1 2
D. 0 1 2
E. Compilation Error
Topic: final Keyword In Java Static Keyword In Java

If you need explanation Read this topic 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 C. First  switch case evaluate 2 since k = 0 matches with i-2 (2-2) and for each value it satisfies the following cases will be executed since there is no break statement.

Posted by Nikhil Sulibhavi    2014-08-13 12:49:03


Ans: is C "212012"

Posted by Necheer Nls    2014-08-13 15:55:52


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

Posted by Merit Campus    2014-08-14 04:12:57


© meritcampus 2019

All Rights Reserved.

Open In App