Computer Applications
Predict the output of the below Java program snippet:
c = (val + 550 < 1700)? 200: 400;
if: (a) val = 1000 (b) val = 1500
Java
Java Operators
53 Likes
Answer
(a) 200
(b) 400
Working
When val = 1000, val + 550 = 1550. As 1550 is less than 1700 so condition of ternary operator is true. Variable c is assigned the value of expression 1 which is 200.
When val = 1500, val + 550 = 2050. As 2050 is greater than 1700 so condition of ternary operator is false. Variable c is assigned the value of expression 2 which is 400.
Answered By
30 Likes
Related Questions
Predict the output of the below Java program snippet:
int x = 90; char c = (x<=90)?'Z':'I';
Predict the output of the below Java program snippet:
int a = 18; int b = 12; boolean t = (a > 20 && b < 15)? true : false;
If the value of basic=1500, what will be the value of tax after the following statement is executed ?
tax = basic > 1200 ? 200 : 100;
What is an operator? What are the three main types of operators? Name them.