हिंदी

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 = (++b)* b - a

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.

f = (++b)* b - a

मूल्यांकन
Advertisements

उत्तर

a = 5, b = 3, d = 1.5

Data types: a, b, c are integers, while d and f are floating-point numbers.

Expression: f = (++b) * b - a

In Java, the pre-increment operator (++b) increases the value of b by 1 before using it in the expression.

Original value of b = 3

Updated value of b = 4

Value used by ++b = 4

f = (++b) × b − a

f = 4 × 4 − 5

f = 16 − 5

f = 11

Since a and b are integers, the expression produces an integer result of 11. As f is a floating-point variable, Java automatically converts the integer result into a floating-point value.

f = 11.0 and b = 4.

shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 6: Variables and Expressions - EXERCISE [पृष्ठ १३२]

APPEARS IN

धीरज मेहरोत्रा Computer Science [English] Class 12
अध्याय 6 Variables and Expressions
EXERCISE | Q 36. (d) | पृष्ठ १३२
Advertisements
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×