Answer:
// calculate its cosine
double result = Math.cos( Math.toRadians(degrees) );
Function Results as Arguments
You may have noticed that one function is nested inside another:
double result = Math.cos( Math.toRadians(degrees) );
This is perfectly fine, and is a reasonable way to write the code.
As long as the inner function returns a value that is correct for the outer
function this works fine.
In fact, we could combine this line with the println():
// calculate its cosine and print the result
System.out.println("cosine: " + Math.cos( Math.toRadians(degrees) ) );
It is a matter of taste, sometimes, how much to combine computations into one statement. Your goal should be to make the logic clear, not to save typing.
QUESTION 22:
Which page in this chapter is your favorite?