3 ms·
I don't get example 3. What's wrong with a negative percent?
by planteen 11y ago
I don't get example 3. What's wrong with a negative percent?
- eveningcoffee 11y agoPerhaps nothing, but he made an assumption that this would be wrong in this case (if it is is matter of discussion). But he did not give a way to fix this idiomatically: public String format(int percentage) { if (percentage < 0) { throw new IllegalArgumentException("Negative percentage not allowed."); } return percentage + "%"; }