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)
- Given x = 4; and y = 2; and operator = '-' ; what is the final value of x after the following switch statement is executed? switch (operator) { case '+' : x +=y ; break ; case '-' : x -= y ; break ; x += y ; is x = x + y ; case '*' : x *= y ; break ; case '/' : x /= y ; break ; default : break ; also, using x = 4 ; and y = 2 ; and operator = ' * '. What is the final value of x? }arrow_forwardSubject-advance mathsarrow_forwardDiscuss when you would choose to use multiple if statements versus a switch statement and vice versa. Explain your answer.arrow_forward
- HW5: Write a program in C language by using if statement for the gear system in automatic cars, where the letters represent the car status. P: Park , R : Reverse , N : Neutral , D : Drive , L: Low Drive.arrow_forwardWrite the following for statement as a while statement. for (k = 0; k < 3; k++) { System.out.println (“Hello”); }arrow_forward1. By using the aid of flowchart(s), explain the difference between if selection and if.. else selection.arrow_forward
- A variable in a program is a named placeholder that can contain any integer value. The statementz + e replaces the old value of the variable x with the result of evaluating the expression e. For example, if x initially contains 7 then the statement I + 1 +1 results in x containing 8. If the variables x, y and z initially contain the values 7, -2, and 8 respectively. What will be the value of y after the following statements are executed, in order, twice: I + I + z - y - y + z 2 O -19 35 29 21 O None of the other answers are correctarrow_forward6. Write a program segment using switch selection for the following statements. If the grade is A, print “Your CGPA is 4.0". If the grade is B, print “Your CGPA is 3.0". If the grade is C, print “Your CGPA is 2.0". If the grade is D, print “Your CGPA is 1.0".arrow_forwardPLEASE DO ANSWER FAST WITH IN 30 MINSarrow_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