Rewrite the following using ternary operator : if (bill > 10000) discount = bill * 10.0 / 100; else discount = bill * 5.0 / 100;
Advertisements
Question
Rewrite the following using ternary operator :
if (bill > 10000)
discount = bill * 10.0 / 100;
else
discount = bill * 5.0 / 100;One Line Answer
Advertisements
Solution
double discount = (bill > 1000) ? bill * 10.0 / 100 : bill * 5.0 / 100;shaalaa.com
Introduction of Operators in Java
Is there an error in this question or solution?
Chapter 1.04: Operators in Java - EXERCISES [Page 44]
