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. f = a + b/a
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.
f = a + b/a
Evaluate
Advertisements
Solution
a = 5, b = 3
Expression: f = a + b/a
In Java, both a and b are integers, so integer division is performed.
\[ f=a+\frac{b}{a} \]
\[ f=5+\frac{3}{5} \]
f = 5 + 0
f = 5.0
shaalaa.com
Is there an error in this question or solution?
