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;
}
}
}
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;
}
}
}
A. 0
B. 1
C. 2
D. 3
E. 1 2
Answer: Option E
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