English

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?
Chapter 6: Variables and Expressions - EXERCISE [Page 132]

APPEARS IN

Dheeraj Mehrotra Computer Science [English] Class 12
Chapter 6 Variables and Expressions
EXERCISE | Q 36. (a) | Page 132
Advertisements
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×