Computer Applications
Predict the output of the following:
System.out.println(Math.round(-18.51));
Java
Java Math Lib Methods
40 Likes
Answer
-19
Working
Math.round method rounds off its argument to the nearest mathematical integer and returns its value as an int or long type. At the mid-point i.e. when the decimal part of the argument is 0.5, Math.round method rounds up to the higher integer. In this case, the nearest integer to -18.51 is -19 so it is the output.
Answered By
25 Likes
Related Questions
Predict the output of the following:
System.out.println(Math.ceil(-0.95));
Predict the output of the following:
System.out.println(Math.min(-25.5, -12.5));
Predict the output of the following:
System.out.println(Math.floor(-0.88));
Predict the output of the following:
System.out.println(Math.max(-77.66, -87.45));