Thursday 28 December 2017

2.3 Switch Case

Switch case in java is used when you have to use multiple if else statements.


class SwitchCase
{
public static void main(String args[])
{
int n=4;
switch(n)
{
case 1:
System.out.println("One");
break;
case 2:
System.out.println("Two");
break;
case 4:
System.out.println("Four");
break;
default:
System.out.println("Some number");
}

// if you not use break then all the out statement after the case match will print
// Switch case can be used with String , character as well.
}
}

No comments:

Post a Comment