English

Rewrite the following using ternary operator : if (bill > 10000) discount = bill * 10.0 / 100; else discount = bill * 5.0 / 100; - Computer Applications

Advertisements
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]

APPEARS IN

Avichal Computer Applications [English] Class 10 ICSE
Chapter 1.04 Operators in Java
EXERCISES | Q V. 8. (b) | Page 44
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×