Re-write following if-else-if statements as Switch statement. Your final code should result in the same output as the original code below.
if (selection == 10) System.out.println("You selected 10.");
else if (selection == 20) System.out.println("You selected 20.")
; else if (selection == 30) System.out.println("You selected 30.");
else if (selection == 40) System.out.println("You selected 40.");
else System.out.println("Not good with numbers, eh?");
switch(selection){ case 10: System.out.println("You selected 10."); break; case 20: System.out.println("You selected 20."); break; case 30: System.out.println("You selected 30."); break; case 40: System.out.println("You selected 40."); break; default: System.out.println("Not good with numbers, eh?"); }
Get Answers For Free
Most questions answered within 1 hours.