Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 3.9, Problem 3.27CP
What is wrong with the following switch statement?
// This code has errors!!!
switch (temp)
{
case temp < 0 :
System.out.println(“Temp is negative.”);
break;
case temp = 0;
System.out.println(“Temp is zero.”);
break;
case temp > 0 :
System.out.println(“Temp is positive.”);
break;
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Given x = 4; and y = 2; and operator = " ;
%3D
%3D
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;
Similarly to question in number 2, using
X = 4 ; and y = 2; and operator ='*'.
%3D
What is the final value of x?
Nested if-else statements and switch statements both allow for multi-way selection. When would it not be advisable to use a switch statement?
Note: The switch() statement is discussed in Special Topic 3.3 as well as here: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html
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?
}
Chapter 3 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th 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 - Prob. 3.19CPCh. 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 - Prob. 3.30CPCh. 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 - Prob. 5SACh. 3 - What risk does a programmer take when not placing...Ch. 3 - Prob. 7SACh. 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 - Prob. 15PCCh. 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
Answer question 3.33, but do not consider any pet having the breed of Unknown.
Database Concepts (8th Edition)
What is the largest numeric value that could be represented with three bytes if each digit were encoded using o...
Computer Science: An Overview (12th Edition)
The least common multiple (1cm) of two positive integers u and v is the smallest positive integer that is evenl...
Programming in C
File Display Program Write a program that asks the user for the name of a file. The program should display the ...
Starting Out with C++ from Control Structures to Objects (8th Edition)
A(n) ______ is a special value that signals when there are no more items from a list of items to be processed. ...
Starting Out with Programming Logic and Design (4th Edition)
Figure 4-3212 shows a class list for Millennium College. Convert this user view to a set of 3NF relations using...
Modern Database Management (12th 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
- What is z after the following switch statement is executed? int i 10; int z -1; switch (i) { case 10: z = 10; case 20: z = 20; break; default: z } O -1 O 20 O 10arrow_forwardswitch (i){case 1:printf(" Case1 "); break;case 2:printf(" Case2 "); break;case 3:printf(" Case3 "); break;case 4:printf(" Case4 "); break;default:printf(" Default ");arrow_forwardprogramming language c++arrow_forward
- Programming Language: C++arrow_forwardTransform 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_forwardWhat is a value of y after the following switch statement is executed? int x = 3; int y = 4; switch (x + y) { case 6: y = 0; case 7: y = 1; default: y += 1; } O A. 3 OB. 2 O C.4 D. 1arrow_forward
- Exercise 7-2: Accumulating Totals in Single-Level Control Break Programs In this exercise, you will use what you have learned about accumulating totals in a single-level control break program. Study the following code, and then answer Questions 1-4. if(sectionNum != oldSectionNum) { System.out.println("Section Number " + oldSectionNum); totalSections %3D oldSectionNum he = SEL onNum%3; } ole, 1. What is the control break variable? :as 2. The value of the control break variable should never be changed. True or false? 3. Is totalSections being calculated correctly? n the If not, how can you fix the code? to ** In a control break program, it doesn't matter if the records in the input file are in a specified order. True or false?arrow_forwardPROGRAMMING LANGUAGE: C++ TASK 1. You are required to create a simulation of an elevator system. There are 7 floors in a building. A user may enter the elevator and press the button of the destined floor. The simulation should display appropriate messages while moving towards the destined floor. Task 2. Write a program that takes +,-,*, and / operators and performs the required operation. the program will continue to execute until ESC key is pressed. Also, the usage of post-test loop and switch statement is mandatory.arrow_forwardI want the flowchart of this codearrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
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