मराठी

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

c = (a++)*d + 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: c = (a++) * d + a

c = (a++) × d + a

In Java, the post-increment operator uses the original value of a first and then increases it by 1.

Original value of a = 5

Value used by a++ = 5

Updated value of a = 6

c = 5 × 1.5 + 6

c = 7.5 + 6

c = 13.5

In Java, d is a floating-point variable, while a is an integer. Therefore, multiplication produces a floating-point result.

The calculated value is 13.5, but the given expression produces a compilation error because a double value cannot be directly assigned to an int variable.

shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 6: Variables and Expressions - EXERCISE [पृष्ठ १३२]

APPEARS IN

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

Englishहिंदीमराठी


      Forgot password?
Use app×