ExamVeda
Login
Home
This question belongs to Java Program Flow Control
Flow Control
?

What all gets printed when the following program is compiled and run.
public class Test{
      public static void main(String args[]){ 
            int i, j=1;
            i = (j>1)?2:1;
            switch(i){
                  case 0: System.out.println(0); break;
                  case 1: System.out.println(1);
                  case 2: System.out.println(2); break;
                  case 3: System.out.println(3); break;
            }
      }
}

Answer & Solution
Correct Answer: Option E
Let's discuss the solution. Join the discussion
Examveda
Question posted by Examveda
Community

Join the Discussion

1 Comment
Ram Ran
Ram Ran 9 years ago
j>1 is false so i=1
switch statement switch(1)
case 1 is execute and not used break statement for case 1.
so case 2 also executed
now case 1 print :1
case 2 print:2
output should be 1 2