Switch statements are commonly applied in most of the programming languages and in java too . Switch statement accepts two datatypes , char and int till java 6. But now java 7 has added a feature where switch statement can accept string values too . It matches the string with the cases and executes the code. Please see the following program for more understanding .
String s = ….;
switch(s)
{
case "subbu":
System.err.println("It is subbu man!");
break;
case "ryan":
System.err.println("It is ryan man!");
break;
case "john":
default:
System.err.println("Default");
break;
}
String s = ….;
switch(s)
{
case "subbu":
System.err.println("It is subbu man!");
break;
case "ryan":
System.err.println("It is ryan man!");
break;
case "john":
default:
System.err.println("Default");
break;
}
No comments:
Post a Comment