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
Write a Java statement for the following mathematical expression :
V = πr2h
Write the value of n and m after execution of the following code.
int m; int n; m = 5; n = (5 * ++m) % 3; System.out.println("n = " + n + "m =" + m);If a = 24, b = 15, find the value of:
a += b++ * 5 / a++ + bGive the prototype of a function search, which receives a sentence sentc and a word wrd and returns 1 or 0.