KnowledgeBoat Logo
|

Computer Applications

Predict the output of the following.

(a) Math.pow(2.5, 2) + Math.ceil(5)

(b) Math.round(2.9) + Math.log(1)

Java Math Lib Methods

5 Likes

Answer

(a) 11.25

(b) 3.0

Explanation

(a) Math.pow(x, y) method returns the value of x raised to the power of y. Math.ceil() method returns the smallest double value that is greater than or equal to the argument and is equal to a mathematical integer. Thus, the given expression is evaluated as follows:

Math.pow(2.5, 2) + Math.ceil(5)
⇒ 6.25 + 5.0
⇒ 11.25

(b) Math.round() method rounds off its argument to the nearest mathematical integer and returns its value as an int or long type. Math.log() method returns the natural logarithm of its argument. Thus, the given expression is evaluated as follows:

Math.round(2.9) + Math.log(1)
⇒ 3 + 0.0
⇒ 3.0

Answered By

1 Like


Related Questions