Math Class
Help Questions
AP Computer Science A › Math Class
A building height uses height = distance * Math.sin(Math.toRadians(angleDeg)); why call Math.toRadians first?
Because Math.sin expects its argument in radians, not degrees.
Because Math.sin only works for angles between 0 and 90 degrees.
Because Math.toRadians returns the sine value directly as a double.
Because Math.toRadians prevents integer division when computing height.
Explanation
This question assesses understanding and application of Java Math class methods within the context of AP Computer Science A. The Math class in Java provides static methods for performing basic numeric operations such as exponentiation, square root, and trigonometric functions. In this scenario, students must understand why Math.toRadians is called before Math.sin when working with degree measurements. Choice A is correct because Math.sin expects its argument in radians, not degrees, so conversion is necessary for correct results. Choice B is incorrect because Math.sin works for any angle in radians, not just 0-90 degrees. Encourage students to always check whether trigonometric inputs are in degrees or radians, as using degrees directly in Math.sin will produce incorrect results. Practice with real-world trigonometry problems helps reinforce the importance of unit conversion.