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 3 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Additional Engineering Textbook Solutions
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Database Concepts (8th Edition)
Java: An Introduction to Problem Solving and Programming (7th Edition)
Database Concepts (7th Edition)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Problem Solving with C++ (10th Edition)
- Transform this switch into nested if statements switch (phrase.charAt (index)){case ' ': blankcount++;break;case 'a':case 'A' : Acount++;break;case 'e':case 'E':Ecount++;break;case 's':case 'S':Scount++;break;case 't':case 'T':Tcount++;break;}}arrow_forward3- Enter a=3; b=5; e=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_forward
- Convert 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_forwardsoleve 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_forwardSubject-advance mathsarrow_forward
- Discuss when you would choose to use multiple if statements versus a switch statement and vice versa. Explain your answer.arrow_forward1. Write any two differences between if-else and switch statement. if-else switcharrow_forward3. Write a program to display the grade and grade point for a subject when the user key in their mark using if.else if statement. Your program should allow the user to repeat this grading for another mark of subject. TABLE Marks Grade Point 80 - 100 A 4.0 75 - 79 A- 3.7 70 - 74 B+ 3.3 65 - 69 3.0 60 - 64 В- 2.7 55 - 59 C+ 2.3 50 - 54 C 2.0 47 - 49 C- 1.7 44 - 46 D+ 1.3 40 - 43 D 1.0 00 - 39 Earrow_forward
- Write a program that reads student scores, gets the best score, and hence assigns grades based on the following scheme: Grade is A if score is > = best - 10; Grade is B if score is > = best - 20; Grade is C if score is > = best - 30; Grade is D if score is > = best - 40; Grade is F otherwise. The program prompts the user to enter the total number of students, then prompts the user to enter all of the scores, and concludes by displaying the grades. Language: C++arrow_forwardExercise: Complete the switch statement, and add the correct keyword at the end to specify some code to run if there is no case match in the switch statement. int day = 4; switch (day) { case 1: cout << "Saturday"; break; case 2: cout << "Sunday"; break; default): cout << "Weekend"; } Show Answerarrow_forwardthis is c program Write program that ask the user to enter int mark (0-100) for test Physics. Thencategorise the student based on the following grading system. Use else-if and switchstatements.Value output80-100 Gred A; Excellent60-79 Gred B; Very Good.40-59 Gred C;Good.0-39 Gred F;Failarrow_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