Q1: 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?");
Q2:
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;
}
Q1: 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?"); } Q2: int total = 0; do { System.out.println("you can still buy for"+(100-total)+"Dollars"); total=total+5; }while(total<100);
Get Answers For Free
Most questions answered within 1 hours.