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 (3rd Edition)
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)
- Write a selection statements to to check whether the values of two variables i and j are divisible by 5, only i is divisible by 5, only j is divisible by 5, both i and j are not divisible by 5. It should display appropriate message for each case, for example, if the values of two variables i and j are divisible by 5 then it should display "Both i and j are divisible by 5". T TT Arial 3 (12pt) T KAarrow_forwardQ7-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_forward
- 3- Enter a=3; b=5; e=7, then clear the variable b only Matlabarrow_forwardGiven 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_forwardRewrite 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_forward
- Implement 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_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_forward1. In which cases you can transform an else-if statements to switch? Provide an example.arrow_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_forwardThere are no combination of looping and conditional statement here.arrow_forwardDiscuss when you would choose to use multiple if statements versus a switch statement and vice versa. Explain your answer.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