Paul Clapham wrote:
As Campbell suggests, there is more beyond that; your requirements don't mention that "n" must be greater than zero, for example, but they also don't say what should happen if a negative number is input.
One of the first things taught in a Calculus course is the concept of
domain and
range. That is, what is allowed to go in and what is allowed to come out.
I consider that an essential part of the documentation of any software function, but alas, in the Real World, it is often not present. Of course, in addition to domain and range, proper documentation of a software function should also include exceptions and exception handling. What the function's invoker should do if the function fails/is presented with unacceptable data and what the function will do internally when an internal problem is discovered.
The Javadoc comment system is a good way to provide such documentation right alongside the code. I encourage its use. In fact, where reasonable, code samples I post here on the Ranch will include Javadoc comments.