Computer Applications
Rewrite the following using ternary operator:
if (bill > 10000)
discount=bill*10.0/100;
else
discount=bill*5.0/100;
Java
Java Operators
ICSE 2018
100 Likes
Answer
discount = bill > 10000 ? bill*10.0/100 : bill*5.0/100;
Answered By
57 Likes
Related Questions
Rewrite the following program segment using if-else statements instead of the ternary operator:
c = (x >= 'A' && x<= 'Z') ? "Upper Case Letter" : "Lower Case Letter";
Rewrite the following using ternary operator:
if(income < 10000) tax = 0; else tax = 12;
Rewrite the following using ternary operator:
if(a > b) { if (a > c) g = a; else g = c; } else if (b > c) g = b; else g = c;
Rewrite the following using ternary operator:
if (x % 2 == 0) System.out.println("Even"); else System.out.println("Odd");