Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
If you ain't using 3 loops, you ain't trying!
This comment is hidden because it contains spoiler information about the solution
Sometimes the answer is right in front of you... Looking at this makes me feel a bit silly about my solution :D
You shoul calculate percent/100 before while. And you might add +1. i.e. percent = percent/100 + 1. Cause x + x*0.1 = x.1.1
One small performance change. I would calculate "percent / 100D" before the while loop in order to prevent the slight extra work added for each pass. The rest is much cleaner than mine :)
From the perspective of the code that calls the method it doesn't matter at all, in Java parameters are always passed by value. Whether method code should be allowed to reassign parameter variables or not is primarily opinion based or just a matter of taste. With short code like this I personally don't see more disadvantages when modifying p0 compared to declaring another variable which might be considered additional noise. And with rather long or complex method code you have a different problem anyway: You're unable to quickly understand what it does anyway.
I agree. The arguments should remain consistent throughout the function and a local variable used in-favour of modifying the argument.
@AndreaLaforgia, in practice you should never "expect" too much about code; anything not declared
final
is modifiable.IMO best practice is make code intent clearer by getting into habit of using
final
modifier wherever appropriate - eg Unless you are going to changep0
then it should be declaredfinal p0
.+1 for using the += operation to cast to int and auto floor it! We can't increase the population by 0.25 of a person.