Evaluate the following Java expression, where a, b and c are integers and d and f are floating-point numbers. The values are a = 5, b = 3 and d = 1.5. c = d*a + b
Advertisements
प्रश्न
Evaluate the following Java expression, where a, b and c are integers and d and f are floating-point numbers. The values are a = 5, b = 3 and d = 1.5.
c = d*a + b
मूल्यांकन
Advertisements
उत्तर
a = 5, b = 3, d = 1.5
Expression: c = d * a + b
In Java, multiplication is performed before addition.
c = d * a + b
c = 1.5 * 5 + 3
c = 7.5 + 3
c = 10.5
Since c is an integer variable, a double value cannot be assigned to it directly without explicit type casting.
Compilation Error (possible lossy conversion from double to int).
shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
