KnowledgeBoat Logo

Output Questions for Class 10 ICSE Computer Applications

Predict the output of the following:

System.out.println(Math.rint(-99.4));

Java

Java Math Lib Methods

ICSE

36 Likes

Answer

-99.0

Working

Math.rint method rounds off its argument to the nearest mathematical integer and returns its value as a double type. The nearest integer to -99.4 is -99.0 so that is the output. Math.rint 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(1.5) and Math.rint(2.5) will both return 2.0. In the case of 1.5, both 1.0 and 2.0 are equally close to 1.5. Math.rint choses the integer that is even so 2.0 is returned. In the case of 2.5, both 2.0 and 3.0 are equally close to 2.5. Math.rint again choses the integer that is even so 2.0 is returned.

Answered By

23 Likes