// calculate its cosine
double result = Math.cos( Math.toRadians(degrees) );
One function call is nested inside another. The value that the nested function returns becomes the parameter for the outer function.
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.
In fact, you could nest the function calls within 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 put in one statement. Your goal should be to make the logic clear, not to save typing.
Can Java compute ex
?