Question: Convert the following if-else-if statement into a switch statement: if (choice == 1) { System.out.println(You selected 1.); } else if (choice == 2 || choice

Convert the following if-else-if statement into a switch statement: 

if (choice == 1)
{
 System.out.println("You selected 1.");
}
else if (choice == 2 || choice == 3)
{
 System.out.println("You selected 2 or 3.");
}
else if (choice == 4)
{
 System.out.println("You selected 4.");
}
else
{
 System.out.println("Select again please.");
}

Step by Step Solution

3.42 Rating (168 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

switch choice case 1 SystemoutprintlnYou selected ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Starting Out With Java From Control Structures Questions!