The switch statement in java language is used to execute the code from multiple conditions or case. It is same like if else-if ladder statement.
A switch statement work with byte, short, char and int primitive data type, it also works with enumerated types and string.

                                    

Syntax :  switch(Expression/Variable)
 
                    {
                            case value:

                      //satements

                       // any number of case statements

                        break ;  //optional

                                default :  //optional
                                //statements
                    }
                           

Rules for apply switch statement

With switch statement use only byte, short, int, char data type (float data type is not allowed). You can use any number of case statements within a switch. Value for a case must be same as the variable in switch.

Program:

import java.util.*; class switchCase { public static void main(String arg[]) { int ch; System.out.println("Enter any number (1 to 7) :"); Scanner s=new Scanner(System.in); ch=s.nextInt(); switch(ch) { case 1: System.out.println("Today is Monday"); break; case 2: System.out.println("Today is Tuesday"); break; case 3: System.out.println("Today is Wednesday"); break; case 4: System.out.println("Today is Thursday"); break; case 5: System.out.println("Today is Friday"); break; case 6: System.out.println("Today is Saturday"); break; case 7: System.out.println("Today is Sunday"); default: System.out.println("Only enter value 1 to 7"); } } }

Output:

Enter any number (1 to 7) : 5 Today is Friday

  • Progamming is what actually means ?
  • What is software development ?
  • How we categorized software development in different manner.
C Programming
C Plus Plus
Python
Java Development
Web Designing
Javascript
Mysql
Oracle
We cover all the programming concepts in various programming languages, this tutorials are very help full for bigener as well as Experience developer, for the ease of understanding we categorized programming in different manner likewise.