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
- Write the Java statement for the following mathematical expression: 
- Give the output of the following expression, when a = 6. - a += ++a + a++ + a-- + a-- + --a + ++a
- Write a program to input a number. Check and display whether it is a Niven number or not. (A number is said to be Niven which is divisible by the sum of its digits). - Example: Sample Input 126 
 Sum of its digits = 1 + 2 + 6 = 9 and 126 is divisible by 9.
- Write a program to accept 10 different decimal numbers (double data type) in a Single Dimensional Array (say, A). Truncate the fractional part of each number of the array A and store their integer part in another array (say, B).