Page 30 - PowerPoint Presentation
P. 30

switch Statement









            •      switch is another control structure to implements multiway branches



            •      Use switch expression (integer expression) to determine which branch to be executed



            •      Use break statement to jump to the next statement after the switch statement




            Before Java 7:


            The type of the Expression must be char, byte, short, int. you can’t use String.



            https://stackoverflow.com/questions/5198671/does-the-switch-statement-in-java-only-work-with-


            integers


            After Java 7: you can use String in switch
   25   26   27   28   29   30   31   32   33   34   35