KnowledgeBoat Logo
|

Computer Applications

State the value and type of each expression.

Math.round(1.49) + 0.1

Java Math Lib Methods

2 Likes

Answer

The output value is 1.1. The type of expression is long.

Explanation

Math.round() rounds off its argument to the nearest mathematical integer.

    Math.round(1.49) + 0.1
⇒ 1 + 0.1
⇒ 1.1

If argument is float, return type is int, if argument is double, return type is long. In this case, 1.49 will be treated as double because suffix 'f' is not there. Hence, it will return a value of long data type.

Answered By

1 Like


Related Questions