This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
1- Obviously, this code doesn't even compile 2- Sun's docs say: "The break statements are necessary because without them, the case statements fall through. That is, without an explicit break, control will flow sequentially through subsequent case statements."
Here is a small program that shows the syntax of switch. I hope this helps to understand how it works. Please compile and substitute different values for i at the beginning in order to see how the switch operates.
Your Code will chk for the first value that matches the case ...It will then execute everything after that till it come to a break or till it exits the block So if u try out a system.out.println() after each case:i++ u will c what i mean .As such i is incremented aneeway. If your first case isn't 1 then it will search for the value which matches i and then execute all other cases therafter including your default case. If there is break aneewhere in between it will as is obvious break out of the switch statement. Cheers