Question: Rewrite the following if-else statements as statements that use the conditional operator. a) if (x > y) z = 1; else z = 20; b)

Rewrite the following if-else statements as statements that use the conditional operator. 

a) if (x > y)
 z = 1;
else
 z = 20;

b) if (temp > 45)
 population = base * 10;
else
 population = base * 2;

c) if (hours > 40)
 wages *= 1.5;
else
 wages *= 1;

d) if (result >= 0)
 System.out.println("The result is positive.");
else
 System.out.println("The result is negative.");

Step by Step Solution

3.32 Rating (161 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Solution a z x y 1 20 b populatio... 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!