What is the output of the given java program?
public class HelloWorld
{
public static void main(String []args)
{
int i = 1024<<8<<3>>8>>3;
switch(i)
{
default : break;
case 1048576/(34*32) : System.out.println("Case 1");
case 1073741824/(2*32*4*32*16*8*2) : System.out.println("Case 2");
case 1048576/(32*30*4) : System.out.println("Case 3");
}
}
}
-
Case 1Case 2Case 3
-
Case 2 Case 3
-
Case 3
-
No output
-
Compiler Error
D
Correct answer
Explanation
This is the correct, no output will be printed on the screen. The expression (int i = 1024<<8<<3>>8>>3;) given in theCode Evaluates to 1024. So the value of variable i is 1024. The expression will be evaluated as :-(1024*(2^8)*(2^3)) / ((2^8)/(2^3)). So the value of the variable I is now 1024.Now switch will find a case having value 1024, but there is no case label having value 1024.So the Default case will be executed, but there is no statement in the Default case. So no output will be printed on the screen. So this answer is correct.