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?");
Second question
Re-write following while loop into Java statements that use a Do-while loop. Your final code should result in the same output as the original code below.
int total = 0;
while(total<100)
{
System.out.println("you can still buy for"+(100-total)+"Dollars");
total=total+5;
}
Get Answers For Free
Most questions answered within 1 hours.