Home / Questions / Rewrite the following code using the if-else statement: int m = 400; double ch = (m>300) ? (m / 10.0) * 2 : (m / 20.0) - 2;
Explanatory Question

Rewrite the following code using the if-else statement:

int m = 400;
double ch = (m>300) ? (m / 10.0) * 2 : (m / 20.0) - 2;

👁 62 Views
📘 Detailed Answer
🕒 Easy to Read
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.

Answer with Explanation


int m = 400;
double ch = 0.0;
if(m > 300)
    ch = (m / 10.0) * 2;
else
    ch = (m / 20.0) - 2;