SWITCH CASE
switch (exp)
{
case constant 1;
statement;
break;
case constant 2;
statement;
break;
_____________
________
________
default;
statement;
}
RULES FOR SWITCH CASE :=
1.) CASE CONSTANTS MUST BE OF TYPE INT OR CHAR.
2.) NO TWO CASE MAY BE SAME.
3.) BREAK IS OPTIMAL.
4.) DEFAULT IS OPTIMAL.
EXAMPLE
class color
{
public static void main (string args[])
{
char ch = args[0.].char At(0);
switch(ch)
{
case "R":
system.out.println("RED");
break;
case "G":
system.out.println("GREEN");
break;
case "B":
system.out.println("BLUE");
break;
default;
system.out.println("UNDEFINED");
}
}
}
AS SAME WE CAN MAKE A CALCULATOR OR MORE OTHER PROGRAMS.
No comments:
Post a Comment