·  JAVA – Syntax – Conditional Statements – switch ... case


- Info:

  - This tutorial shows how to use conditional statement "switch...case".

  - Switch statement must have single int or char parameter whose value is used to determine which case to execute.

  - If there is no case with that value, default case is executed, and it doesn't have to be placed at the end.

  - During execution of case body, break statement brakes from switch block.

    If there is no break statement program continues with the next case or default case until the end of switch block.


- Procedure:

  - Create JAVA Console Application Test.java



    public class Test {


      public static void main (String arg[]) throws Exception {


        int a = 5;

        switch (a) {

          case 1:

            System.out.println("Value is 1. Exit from switch.");


          case 5:

            System.out.println("Value is 5. Continue to next case or default.");


            System.out.println("Default value is selected if no case was true.");