Java | Switch Statement: Switch statement is the one of the conditional statement. It provide the multiple options to choose the one of them by checking the condition.
Syntax: switch ( condition )
{
case 1:
// statements...
break;
case 2:
// statements...
break;
default:
// statements...
}
Here is the Code:
- import java.io.*;
- class Main {
- public static void main (String[] args) {
- int i = 3;
- switch(i)
- {
- case 1:
- System.out.println("One");
- break;
- case 2:
- System.out.println("Two");
- break;
- default:
- System.out.println("Out of Range");
- }
- }
- }
Output:
Out of Range
Here is the Video: