Concept explainers
Rewrite the following if-else-if statement as a switch statement.
if (selection == ‘A’)
System.out.println(“You selected A.”);
else if (selection == ‘B’)
System.out.println(“You selected B.”);
else if (selection == ‘C’)
System.out.println(“You selected C.”);
else if (selection == ‘D’)
System.out.println(“You selected D.”);
else
System.out.println(“Not good with letters, eh?”);
Want to see the full answer?
Check out a sample textbook solutionChapter 4 Solutions
Starting Out with Java: Early Objects (6th Edition)
Additional Engineering Textbook Solutions
Experiencing MIS
C++ How to Program (10th Edition)
Computer Systems: A Programmer's Perspective (3rd Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Starting Out with Programming Logic and Design (4th Edition)
Problem Solving with C++ (9th Edition)
- Q7-Write a program that simulates a simple calculator. It reads two integers and a character. If the character is a +, the sum is printed; if it is a -, the difference is printed; if it is a *, the product is printed; if it is a /, the quotient is printed; and if it is a %, the remainder is printed. (Use a switch statement.)arrow_forwardRewrite the if else-if statement using a switch statement: if (fruit 'p' || fruit 'P') == рарayat+; else if (fruit 'b' || fruit 'B') == banana++; else if (fruit 'm' || fruit 'M') == == mango++; else printf("Invalid entry\n");arrow_forwardUsing C Languagearrow_forward
- Rewrite the following code segment using if-else statement instead of switch statement: switch (i) { case 1: printf(" Casel "); break; case 2: printf(" Case2 "); break; case 3: printf(" Case3 "); break; case 4: printf(" Case4 "); break; default: printf(" Default "); } Rewrite the following code segment using switch statement instead of if-else statement: if (operator == '+' C = A+B; else if (operator == - ') C = A-B; else if (operator == *') с = A*B; else if (operator == '/') C = A/B; else error = true;arrow_forwardImplement the following decision table using a nested if statement and multiple alternatives if statement. Assume that the grade point average is within the range 0.0 through 4.0. Do not write entire program. Mention only the required variables and the nested if statement. Grade Point Average Transcript Message 0.0-0.99 Failed semester-registration suspended 1.0–1.99 On probation for next semester 2.0-2.99 (no message) 3.0-3.49 Dean's list for semester 3.5-4.00 Highest honors for semesterarrow_forwardQUESTION 1 Implement the decision structure in the following: Print "spring" if a is equal to b, print "fall" if a is greater than b, otherwise print "break". Use the variables given below: a = 24.0 || b = 24arrow_forward
- 3- Enter a=3; b-5; c=7, then clear the variable b only Matlabarrow_forwardImplement the following decision table using a nested if statement and multiple alternatives if statement. Assume that the grade point average is within the range 0.0 through 4.0. Do not write entire program. Mention only the required variables and the nested if statement. grade point average transricpt message 0.0-0.99 failed semester - resigister suspended 1.0- 1.99 on probation for next semester 2.0-2.99 (no message) 3.0-3.49 dean's list for semester 3.5-4.00 highest honors for semesterarrow_forwardConvert the following if-else-if statement into a switch statement if(choice==1) { System.out.println ("Its a 1."); } else if(choice==2 || choice==3) { System.out.println ("Its a 2 or 3"); } else if(choice==4) { System.out.println ("Its a 4"); else { System.out.println ("um, try again 1 4"); - }arrow_forward
- soleve with c++ use case Write a Mark Sheet program that accepts the marks of the different subjects from the user. Calculate total marks, percentage and grade. If per<60 and per >50 then Grade is "C" If per<70 and per >60 then Grade is "B" If per<80 and per >70 then Grade is "A" If per >80 then Grade is "A-1" If per<50 then prints FAIL.arrow_forward1. Write any two differences between if-else and switch statement. if-else switcharrow_forwardChapter 5 Selection Statement ASSIGNMENT3 1. Using the switch statement, write a program that converts a numerical grade into a letter grade: Enter numerical grade: 84 Letter grade: B Use the following grading scale: A = 90~100, B = 80~89, C = 70~79, D = 60~69, F = 0~59. Print an error message if the grade is larger than 100 or less than 0. Hint: Break the grade into two digits, then use a switch statement to test the ten’s digit. 1. Write your program here: #include <stdio.h> int main(){ …… return 0; } 2. Write a program that asks the user for a two-digit number, then prints the English word for the number: Enter a two-digit number: 45 You entered the number forty-five. Hint: Break the number into two digits. Use one switch statement to print the word for the First digit (“twenty” “thirty" and so forth). Use a second switch statement to print the word for the second digit. Don’t forget that the numbers between 11 and 19 require special treatment. 2. Write your…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education