Question: What is wrong with the following switch statement? // This code has errors!!! switch (temp) { case temp < 0 : System.out.println(Temp is negative.); break;

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;
}

Step by Step Solution

3.40 Rating (153 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The comparison operator in the first and second case statements is incorrect It shoul... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Starting Out With Java From Control Structures Questions!