The function argument may be a floating-point number.
The function should return a precise answer.
Code the problem:
Use proper function and variable names.
My function takes an argument which is of type double because even if I pass it any other numerical primitive data type, it will be upcasted to double, by the compiler.
Then comes the logic which solves the problem. Try to be concise and optimize the logic if possible. Why write more, if I can get the problem solved in lesser code.
My function returns a double because it gives me a more precise answer.
A Java programmer's approach:
Understand the problem:
Code the problem:
Output:
Know the limitations of your solution: