ICSE Class 10 Computer Applications Question 26 of 76

Revising Basic Java Concepts — Question 30

Back to all questions
30
Question

Question 14(n)

State the value and type of each expression.

Math.round(1.49) + 0.1
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.