KnowledgeBoat Logo

Output Questions for Class 10 ICSE Computer Applications

Predict the output of the following:

System.out.println(Math.rint(98.5));

Java

Java Math Lib Methods

ICSE

27 Likes

Answer

98.0

Working

Math.rint method rounds off its argument to the nearest mathematical integer and returns its value as a double type. This method behaves in a particular way at the mid-point i.e. when the decimal part of the argument is 0.5. In such cases, the result is the integer value that is even. Let's understand this with an example. Math.rint(97.5) and Math.rint(98.5) will both return 98.0. In the case of 97.5, both 97.0 and 98.0 are equally close to 97.5. Math.rint choses the integer that is even so 98.0 is returned. In the case of 98.5, both 98.0 and 99.0 are equally close to 98.5. Math.rint again choses the integer that is even so 98.0 is returned.

Answered By

11 Likes