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...
Instructions Write a Java code Your goal is to take N integer inputs from the user...
Instructions Write a Java code Your goal is to take N integer inputs from the user -- N's value will be given by the user as well. You can assume the user provides a valid value for N, i.e., >0. Store the input integers in an array of size N in the order they are provided. These tasks should be done in the main() method. Create a new method called checkArray() that will take the previously created array as input...
Modify the following code by JAVA language Write a static method totalDurations that is passed the...
Modify the following code by JAVA language Write a static method totalDurations that is passed the parallel arrays from the main program. It creates a new pair of parallel arrays (phone numbers and durations, again) where each different incoming phone number is stored exactly once, and the duration is the total duration of all the calls from that phone number. It then prints these arrays. Nothing is returned. For example, if the arrays contain 555-1234 (duration 10), 555-4321 (duration 20),...
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...
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
Active Questions
  • Each of the following situations describes a normally distributed population for which a statistical procedure should...
    asked 2 minutes ago
  • Intro to Rehabilitation fill in the blank. A.) This is the type of learning that primarily...
    asked 4 minutes ago
  • A cylindrical capacitor consists of a solid inner conducting core with radius 0.270 cmcm , surrounded...
    asked 4 minutes ago
  • A quality control engineer wants to check whether, in accordance with specification, 90% of the products...
    asked 5 minutes ago
  • Assuming there is ONE risk factor, the interest rate (IR) risk factor. Investors can borrow at...
    asked 8 minutes ago
  • Consider the reaction shown. Using your knowledge of relative acid-base strengths and equilibrium, determine what you...
    asked 11 minutes ago
  • The second assignment will use C++ syntax and control flow stuctures (e.g. loops, switch statements, functions,...
    asked 23 minutes ago
  • Clickable Number Images from Starting out with Visual C# 5th Edition page 113 This is the...
    asked 37 minutes ago
  • Scientists in the nineteenth century who believed that species had not been created once and for...
    asked 51 minutes ago
  • For the database for a symphony orchestra, develop an ER diagram to keep track of all...
    asked 54 minutes ago
  • According to the National Vital Statistics Report, Vol. 52, No. 10, the probability is 0.6591 that...
    asked 58 minutes ago
  • For the reaction shown, calulate the theoretical yield of the product in grams for each of...
    asked 1 hour ago