Login    New User    Forgot Password    Help      

The Switch Statement

Java Tutorials

Unlike if-then and if-then-else statements, the switch statement can have a number of possible execution paths. A switch works with the byte, short, char, and int primitive data types. 

// Switch case
class four
{
public static void main(String args[])
{
int i=10;

switch(i)
{
case 10:
{
System.out.println("Ten");
break;
}
default:
{
System.out.println("Access Denied");
}
}

}
}

Output

e:\java\four Ten

Java Tutorials