Question

Q1: Re-write following if-else-if statements as Switch statement. Your final code should result in the same...

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;

}

Homework Answers

Answer #1
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);
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Re-write following if-else-if statements as Switch statement. Your final code should result in the same output...
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...
Re-write following if-else-if statements as Switch statement. Your final code should result in the same output...
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?");
e-write following if-else-if statements as Switch statement. Your final code should result in the same output...
e-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?"); (Java programming)
1. Given the following multi-way if statement, provide a switch statement, using proper java syntax, that...
1. Given the following multi-way if statement, provide a switch statement, using proper java syntax, that will provide the same function. Char grade; String tstmsg; if (grade == ‘A’) {   tstmsg = “Excellent”; } else if (grade == ‘B’) {   tstmsg = “Good”; } else if (grade == ‘C’) {   tstmsg = “OK”; } else {   tstmsg = “Study More”; } 2.Write the following for statement as a while statement. for (k = 0; k < 3; k++) {   System.out.println...
Write code snippets to do the following. You should write these in a Python editor and...
Write code snippets to do the following. You should write these in a Python editor and test them out as you go. When they work, copy and paste your final code snippet here. Define a function that takes a total bill and the number of people at your table, and prints the amount that each person owes. e.g. divide_bill(100, 5) would produce Each person owes $20 for their meal. e.g. divide_bill(50.25, 4)would produce Each person owes $12.56 for their meal....
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...
USE C++ TO WRITE THIS CODE, MUST USE AN ARRAY An unknown number of grades as...
USE C++ TO WRITE THIS CODE, MUST USE AN ARRAY An unknown number of grades as integers, but no more than 30, are to be read from the file grades.dat. You may assume each grade will be a valid value between 0 and 100 (no validation necessary) and all "grades" are out of a maximum 100 points. Output the Number of Grades read in from the file. Calculate and output the Total Points Earned. Calculate and output the Total Possible...
This is in java and you are not allowed to use Java API classes for queues,...
This is in java and you are not allowed to use Java API classes for queues, stacks, arrays, arraylists and linkedlists. You have to write your own implementations for them. You should construct a BST by inserting node values starting with a null tree. You can re-use the code for the insert method given in the sample code from the textbook. -insert method is provided below Your code should have a menu driven user interface at the command line with...
In java create a dice game called sequences also known as straight shooter. Each player in...
In java create a dice game called sequences also known as straight shooter. Each player in turn rolls SIX dice and scores points for any sequence of CONSECUTIVE numbers thrown beginning with 1. In the event of two or more of the same number being rolled only one counts. However, a throw that contains three 1's cancels out player's score and they mst start from 0. A total of scores is kept and the first player to reach 100 points,...
CAN YOU PLEASE WRITE THIS CODE IN A DIFFERENT WAY 'EASIER AND BETTER' QUESTION Using C++...
CAN YOU PLEASE WRITE THIS CODE IN A DIFFERENT WAY 'EASIER AND BETTER' QUESTION Using C++ 11. Write a function that will merge the contents of two sorted (ascending order) arrays of type double values, storing the result in an array out- put parameter (still in ascending order). The function shouldn’t assume that both its input parameter arrays are the same length but can assume First array 04 Second array Result array that one array doesn’t contain two copies of...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT