Computer Applications
What is the output of the following code?
System.out.println(Math.round(7.5) + Math.floor(2.9));
Java Math Lib Methods
1 Like
Answer
10.0
Reason
Math.round(7.5)rounds to the nearest integer, resulting in 8.Math.floor(2.9)rounds down to the nearest integer, resulting in 2.0 (as adouble).- Adding 8 (an
int) and 2.0 (adouble) produces 10.0 (adoubleresult).
Answered By
3 Likes