Concept explainers
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;
}
Want to see the full answer?
Check out a sample textbook solutionChapter 3 Solutions
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Additional Engineering Textbook Solutions
Problem Solving with C++ (10th Edition)
Concepts Of Programming Languages
Java: An Introduction to Problem Solving and Programming (8th Edition)
Thinking Like an Engineer: An Active Learning Approach (4th Edition)
Introduction To Programming Using Visual Basic (11th Edition)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
- 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.htmlarrow_forwardq1 please fastarrow_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_forward
- int j; switch (i) { case 0: j = 2*i; break; case 1: j = -i; break; default: j = -2*i; } What is j if i = 1? What is j if i = -1?arrow_forwardImplement the switch case switch (A) case 0: { // body a break; } case 1: { // body b break; } default { // body default break; }arrow_forward9. What is the value of x after the following statements are executed? int x = 5; switch (x) { case 5: } a. 6 b. 7 c. 8 x = x + 2; case 6: x = x + 1; break; default: x = x * 2; break; d. e. 10 16arrow_forward
- Observe the following switch statement closely: switch (prompt("What is your mood today?")) { case "happy!": console.log("Yay!"); break; case "Sad".toLowerCase(): console.log("Don't be sad..."); case "upset": console.log("Get glad!"); break;case "UNKNOWN":console.log("How do you not know?"); default: console.log("Are you human?"); break; } MC 3a If input is "happy!", then output is: a) "Yay!" b) "How do you not know?""Are you human?" c) "Are you not human?" d) "Get glad!" MC 3b If input is "Sad", then output is: a) "Get glad!" b) "Don't be sad..." "Get glad!" c) "Are you human?" d) None of the above MC 3c If the input is "UNKNOWN", then the output is: a) "How do you not know?" "Are you human?" b) "How do you not know?" c) "Are you human?" d) None of the abovearrow_forwarddr javaarrow_forwardObserve the following switch statement: switch (prompt("What is your mood today?")) { case "happy!": console.log("Yay!"); break; case "Sad".toLowerCase(): console.log("Don't be sad..."); case "upset": console.log("Get glad!"); break;case "UNKNOWN": console.log("How do you not know?"); default: console.log("Are you human?"); break; } Question 1: If input is "happy!" What is the output? Question 2: If input is"Sad" what is the output? Question 3: If input is "UNKNOWN" what is the output?arrow_forward
- char ch=a'; switch(ch+1 ) { case 'a' :cout<<'a'; break; case 'b' :cout<arrow_forwardthis is the code: const int BLED=9; //Blue LED on Pin 9const int GLED=10; //Green LED on Pin 10const int RLED=11; //Red LED on Pin 11const int Switch=2; //The Button is connected to pin 2boolean lastSwitch = LOW; //Last Button Stateboolean currentSwitch = LOW; //Current Button Stateint ledMode = 0; //Cycle between LED statesboolean ledOn = false;void setup(){ pinMode (BLED, OUTPUT); //Set Blue LED as OutputpinMode (GLED, OUTPUT); //Set Green LED as OutputpinMode (RLED, OUTPUT); //Set Red LED as OutputpinMode (Switch, INPUT); //Set button as input (not required)}}/** LED Mode Selection Pass a number for the LED state and set it accordingly.*/void setMode(int mode){//RED if (mode == 1) { digitalWrite(RLED, HIGH); digitalWrite(GLED, LOW); digitalWrite(BLED, LOW);} //GREENelse if (mode == 2){ digitalWrite(RLED, LOW); digitalWrite(GLED, HIGH); digitalWrite(BLED, LOW); }//BLUE else if (mode == 3) { digitalWrite(RLED, LOW); digitalWrite(GLED, LOW); digitalWrite(BLED, HIGH); } //PURPLE…arrow_forwardI want the flowchart of this codearrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT