Write a program to print a color name using switch statement

Write a program to print a color name using switch statement
class test
{
public static void main(String args[])
{
char color = ‘C';
switch(color)
{
case ‘A’ : System.out.println(“red”);
break;
case ‘B’ : System.out.println(“blue”);
break;
case ‘C’ : System.out.println(“white”);
break;
case ‘D’ : System.out.println(“green”);
break;
default : System.out.println(“no color”);
}
System.out.println(“Your color is ” + color);
}
}

Output:
white
Your color is white

Leave a Reply

Your email address will not be published. Required fields are marked *