Source code, C++ program for using the switch statement to execute a particular task depending on color value.
include <iosteam.h>
include <conio.h>
void main()
{
clrscr();
char color ;
cout<<"Enter any first litter colors";
cin>>color;
switch (color)
{
case ‘r’:
cout<<“red”;
break;
case ‘g’:
cout<<“green”;
break;
case ‘b’:
cout<<“blue”;
break;
case ‘y’:
cout<<“yellow”;
break;
case ‘w’:
cout<<“white”;
break;
default:
cout<<“No Color Selected”;
}
getch();
}
Source code java program for using the switch statement to execute a particular task depending on color value.
//To display a color name depending on color value
import java.until.Scanner ;
class Color
{
public static void main(String []args)
{
char color ;
Scanner sc=new Scanner(System.in);
color=sc.next();
switch (color)
{
case ‘r’:
System.out.println (“red”);
break;
case ‘g’:
System.out.println (“green”);
break;
case ‘b’:
System.out.println (“blue”);
break;
case ‘y’:
System.out.println (“yellow”);
break;
case ‘w’:
System.out.println (“white”);
break;
default:
System.out.println (“No Color Selected”); }
} }
No comments:
Post a Comment