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
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
