Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
7th Edition
ISBN: 9780134802213
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 3, Problem 10AW
Convert the following if-else-if statement into a switch statement:
if (choice == 1)
{
System.out.println(“You selected 1.”);
}
else if (choice == 2 || choice == 3)
{
System.out.println(“You selected 2 or 3.”);
}
else if (choice == 4)
{
System.out.println(“You selected 4.”);
}
else
{
System.out.println(“Select again please.”);
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Please answer in matlab code.
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");
-
}
Rewrite the following using if-else-if structure.
k=2;
switch (i)
case 0:
k+=i;
break;
case 1:
k*=i;
break;
case 2:
case 3:
k/=i;
break;
default:
k%=i;
Chapter 3 Solutions
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Ch. 3.1 - Write an if statement that assigns 0 to x when y...Ch. 3.1 - Write an if statement that multiplies payRate by...Ch. 3.1 - Write an if statement that assigns 0.2 to...Ch. 3.1 - Write an if statement that sets the variable fees...Ch. 3.1 - Write an if statement that assigns 20 to the...Ch. 3.1 - Write an if statement that assigns 0 to the...Ch. 3.1 - Write an if statement that displays Goodbye if the...Ch. 3.2 - Write an if-else statement that assigns 20 to the...Ch. 3.2 - Write an if-else statement that assigns 1 to x...Ch. 3.2 - Write an if-else statement that assigns 0.10 to...
Ch. 3.2 - Write an if-else statement that assigns 0 to the...Ch. 3.3 - Write nested if statements that perform the...Ch. 3.3 - Write code that tests the variable x to determine...Ch. 3.4 - What will the following program display? public...Ch. 3.4 - The following program is used in a bookstore to...Ch. 3.5 - Prob. 3.16CPCh. 3.5 - Assume the variables a = 2, b = 4, and c = 6....Ch. 3.5 - Write an if statement that displays the message...Ch. 3.5 - Write an if statement that displays the message...Ch. 3.6 - Assume the variable name references a String...Ch. 3.6 - Prob. 3.21CPCh. 3.6 - Prob. 3.22CPCh. 3.8 - Rewrite the following if-else statements as...Ch. 3.9 - Complete the following program skeleton by writing...Ch. 3.9 - Rewrite the following if-else-if statement as a...Ch. 3.9 - Explain why you cannot convert the following...Ch. 3.9 - What is wrong with the following switch statement?...Ch. 3.9 - What will the following code display? int funny =...Ch. 3.10 - Assume the following variable declaration exists...Ch. 3.10 - Assume the following variable declaration exists...Ch. 3.10 - Assume the following variable declaration exists...Ch. 3.10 - Prob. 3.32CPCh. 3.10 - Prob. 3.33CPCh. 3.10 - Assume the following declaration exists in a...Ch. 3 - The if statement is an example of a __________. a....Ch. 3 - This type of expression has a value of either true...Ch. 3 - , , and = = are __________. a. relational...Ch. 3 - , | |, and ! are __________. a. relational...Ch. 3 - Prob. 5MCCh. 3 - To create a block of statements, you enclose the...Ch. 3 - This is a boolean variable that signals when some...Ch. 3 - How does the character A compare to the character...Ch. 3 - This is an if statement that appears inside...Ch. 3 - Prob. 10MCCh. 3 - When determining whether a number is inside a...Ch. 3 - Prob. 12MCCh. 3 - The conditional operator takes this many operands....Ch. 3 - This section of a switch statement is branched to...Ch. 3 - You can use this method to display formatted...Ch. 3 - True or False: The = operator and the == operator...Ch. 3 - True or False: A conditionally executed statement...Ch. 3 - Prob. 18TFCh. 3 - True or False: When an if statement is nested in...Ch. 3 - True or False: When an if statement is nested in...Ch. 3 - True or False: The scope of a variable is limited...Ch. 3 - Find the errors in the following code: 1. //...Ch. 3 - Find the errors in the following code: 2. //...Ch. 3 - Find the errors in the following code: 3. //...Ch. 3 - Prob. 4FTECh. 3 - Find the errors in the following code: 5. The...Ch. 3 - Find the errors in the following code: 6. The...Ch. 3 - The following statement should determine whether...Ch. 3 - Find the errors in the following code: 8. The...Ch. 3 - Prob. 9FTECh. 3 - Prob. 10FTECh. 3 - Write an if statement that assigns 100 to x when y...Ch. 3 - Write an if-else statement that assigns 0 to x...Ch. 3 - Using the following chart, write an if-else-if...Ch. 3 - Write an if statement that sets the variable hours...Ch. 3 - Write nested if statements that perform the...Ch. 3 - Write an if statement that prints the message The...Ch. 3 - Write an if statement that prints the message The...Ch. 3 - Write an if statement that prints the message The...Ch. 3 - Write an if-else statement that displays the...Ch. 3 - Convert the following if-else-if statement into a...Ch. 3 - Match the conditional expression with the if-else...Ch. 3 - Prob. 12AWCh. 3 - Prob. 13AWCh. 3 - Prob. 14AWCh. 3 - Explain what is meant by the phrase conditionally...Ch. 3 - Explain why a misplaced semicolon can cause an if...Ch. 3 - Why is it good advice to indent all the statements...Ch. 3 - What happens when you compare two String objects...Ch. 3 - Explain the purpose of a flag variable. Of what...Ch. 3 - What risk does a programmer take when not placing...Ch. 3 - Briefly describe how the operator works.Ch. 3 - Briefly describe how the | | operator works.Ch. 3 - Why are the relational operators called...Ch. 3 - When does a constructor execute? What is its...Ch. 3 - Roman Numerals Write a program that prompts the...Ch. 3 - Magic Dates The date June 10, 1960, is special...Ch. 3 - Body Mass Index Write a program that calculates...Ch. 3 - Test Scores and Grade Write a program that has...Ch. 3 - Mass and Weight Scientists measure an objects mass...Ch. 3 - Time Calculator Write a program that asks the user...Ch. 3 - Sorted Names Write a program that asks the user to...Ch. 3 - Software Sales A software company sells a package...Ch. 3 - Shipping Charges The Fast Freight Shipping Company...Ch. 3 - Fat Gram Calculator Write a program that asks the...Ch. 3 - Running the Race Write a program that asks for the...Ch. 3 - The Speed of Sound The following table shows the...Ch. 3 - Mobile Service Provider A mobile phone service...Ch. 3 - Mobile Service Provider, Part 2 Modify the program...Ch. 3 - Bank Charges A bank charges a base fee of 10 per...Ch. 3 - Book Club Points Serendipity Booksellers has a...Ch. 3 - Wi-Fi Diagnostic Tree Figure 3-23 shows a...Ch. 3 - Restaurant Selector You have a group of friends...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
This statement is like a chain of If statements. They perform their tests, one after the other, until one of th...
Starting Out With Visual Basic (7th Edition)
(Keyword new) Whats the purpose of keyword new? Explain what happens when you use it.
Java How To Program (Early Objects)
Write an if statement that prints the message The number is not valid if the variable hours is outside the rang...
Starting Out with Java: Early Objects (6th Edition)
Look at the second constructor in C1ockDisplay's source code. Explain what it does and how it does it.
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
(Payroll System Modification) Modify the payroll system of Figs20.9.— 20.17 to include private data member bi...
C How to Program (8th Edition)
(You need to do Practice Programs 4 and 7 before doing this one.) Write a program that combines the functions o...
Problem Solving with C++ (10th Edition)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- 3. Convert the following switch statement into if-else statements then into if-then statements: String dayString1, dayString2, dayString3; int day = KB.nextInt (); switch (day) { case 1: dayStringl case 2: dayString2 "Saturday"; "Sunday"; break; case 3: dayString3 = "Monday"; break; case 4: dayStringl = "Tuesday"; case 5: daystring2 = "Wednesday"; break; default: dayString3 = "Invalid day"; break; } 4. Write a program that displays the following pattern: A A A A BB AA A ССС AA AA DDDD AAAΑ EEEEE ΑAAAΑΑ FFFFFFarrow_forwardWrite a statement that assigns finalValue with the multiplication of userNum1 and userNum2. Ex: If userNum1 is 6 and userNum2 is 2, finalValue is 12. let userNum1 = 6; // Code tested with values: 6 and 4let userNum2 = 2; // Code tested with values: 2 and -2 let finalValue = 0;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
- 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_forwardWrite if-else if statements that will compare "price" variable with below values and output statements based on the conditions price>=500 : “Extremely Expensive” price>=300 : “Very Expensive” price>=100: “Reasonable price “arrow_forward
- Assuming X1,X2, Y1 are integer type variables, A,B,C are Bool type variables and Z as real type variable. Check the wrong statements Y1:=(X1 AND X2) +2; if A:=True Then B:=False; End_if; If Z>10 Then Y1:=X1 +4; End_if; C:=(A AND B ) +1; For Z:=1 to 10 Do Y1:=Y1 +1; End_For; While (AB) Do Y1:=Y1+1; End_While;arrow_forward2. Convert the following if statements into switch statements? if (x== 0) { answer = "Condition 1 passed; } else if (x= 10) { answer = "Condition 2 passed"; } else { answer = "No conditions passed"; }arrow_forwardRewrite the following statement using the ternary conditional operator (? :): if (i < 10) { j = 8; } else { j= -2; }arrow_forward
- 5. Write an efficient if statement to assign x the value 1 if x ≤ 1.5, 2 if 1.5arrow_forwardWrite a multiple assignment statement that can be used instead of the followinggroup of assignment statements:east = 1;west = 1;north = 1;south = 1;arrow_forwardWrite a if-elif-else statement that distinguishes between a negative number or 0, a number between 0 and 50, and a number greater than or equal 50 by printing one of these three statements: {"It's negative or zero", "It's between 0 and 50", "It's greater than or equal to 50"}.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
Control Structure in Data Structure - Data Structures - Computer Science Class 12; Author: Ekeeda;https://www.youtube.com/watch?v=9FTw2pXLhv4;License: Standard YouTube License, CC-BY