e. Rewrite the following if statement using the switch statement:
[2]
if (choice == 0)
System.out.print("You selected Blue");
else if (choice 1)
System.out.print("You selected Cyan");
else if (choice 2)
System.out.print("You selected Red");
else if (choice 3)
System.out.print("You selected Magenta");
else
System.out.print("Invalid choice");
Answers
Answer:
switch(choice)
{
case 0:System.out.print ("You selected blue") ;
break;
case 1:System.out.print("You selected cyan") ;
break;
case 2:System.out.print("You selected Red") ;
break;
case3:System.out.ptint("You selected magenta ") ;
break;
default:System.out.print(" Invalid choice") ;
}
mark it brainliest if u get the concept
Question:-
Rewrite the following if statement using switch case.
Solution:-
Given code,
if (choice == 0)
System.out.print("You selected Blue");
else if (choice 1)
System.out.print("You selected Cyan");
else if (choice 2)
System.out.print("You selected Red");
else if (choice 3)
System.out.print("You selected Magenta");
else
System.out.print("Invalid choice");
This can be written using switch case statement as,
switch(choice)
{
case 0:
System.out.print("You selected Blue");
break;
case 1:
System.out.print("You selected Cyan");
break;
case 2:
System.out.print("You selected Red");
break;
case 3:
System.out.print("You selected Magenta");
break;
default:
System.out.print("Invalid choice");
}