Write a function in Java that calculates the difference between the volumes of two cubes. Given two doubles: sideLength1 and sideLength2...
X1531: Difference Of Cubes
Write a function in Java that calculates the difference between the volumes of two cubes. Given two doubles: sideLength1 and sideLength2 (the side lengths of the two cubes), calculate and return the absolute difference between their volumes as a double.
The volume of a cube is side³ (side cubed), but Java doesn't under superscripts.
You should to use Math.pow()
to calculate the cubes in Java.
(e.g. 5³ is equivalent to Math.pow(5, 3)
)
The absolute difference between two numbers is always non-negative.
You should use Math.abs()
to accomplish this.
(e.g. Math.abs(-7)
results in 7
; while Math.abs(8)
results in 8
)
Full example: sideLength1 = 5, sideLength2 = 3.4
volume1 = 5³ = 125.0
volume2 = (3.4)³ = 39.304
difference = |39.304 - 125| = |-85.696| = 85.696
Your Answer:
Feedback
Your feedback will appear here when you check your answer.