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
Question
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
Evaluate
Advertisements
Solution
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
Is there an error in this question or solution?
