Computer Applications

Predict the output

(a) Math.pow(3.4, 2) + 2 * Math.sqrt(64)

(b) Math.ceil(3.4) + 2 * Math.floor(3.4) + 2

Java Math Lib Methods

5 Likes

Answer

(a) 27.56

(b) 12.0

Explanation

(a) Math.pow(x, y) method returns the value of x raised to the power of y. Math.sqrt() method returns the square root of an argument. Thus, the given expression is evaluated as follows:

Math.pow(3.4, 2) + 2 * Math.sqrt(64)
⇒ 11.56 + 2 * 8.0
⇒ 27.56

(b) Math.ceil() method returns the smallest double value that is greater than or equal to the argument and is equal to a mathematical integer. Math.floor() method returns the largest double value that is less than or equal to the argument and is equal to a mathematical integer. Thus, the given expression is evaluated as follows:

Math.ceil(3.4) + 2 * Math.floor(3.4) + 2
⇒ 4.0 + 2 * 3.0 + 2
⇒ 4.0 + 6.0 + 2
⇒ 12.0

Answered By

3 Likes


Related Questions