Solved Sample Paper 1 — Question 25
Back to all questionsQuestion 2(v)
Predict the output
(a) Math.pow(3.4, 2) + 2 * Math.sqrt(64)
(b) Math.ceil(3.4) + 2 * Math.floor(3.4) + 2
(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