What is the result of the following code snippet?
3: int x = 10; 4: switch(x % 4.) { 5: default: System.out.print("Not divisible by 4"); 6: case 0: System.out.print("Divisible by 4"); 7: }
E.
For this problem you need to remember your rules about numeric promotion as well as what data types are allowed in a switch statement.
The expression x % 4.
automatically promotes the x to a double; since 4. is a double, the result is a double.
Because a switch statement does not accept the type double, the code fails to compile due to line 4, so option E is the correct answer.