Advertisements
Advertisements
Question
What will be the output of the given Java code after the calculation [note the data types]?
double fw = Math.pow (3,Math.ceil(2.12));
System.out.println ("FW=" + fw);
Sum
Advertisements
Solution
Math.ceil(2.12);
- The
Math.ceil()method rounds a number upward to its nearest mathematical integer. - 2.12 rounded up becomes 3.0 (returned as a double).
Math.pow(3,3.0);
- This calculates 33 (3 × 3 × 3)
- The result is 27, but since it
Math.pow()always returns a double, it evaluates to 27.0. - FW = 27.0
shaalaa.com
Is there an error in this question or solution?
