I want to subtract one integer from another, and the result should floor at 0. So 2 minus 4 should equal 0. I could just do
int result = x - y;
if (result < 0) result = 0;
But is there a more elegant way?
int result = Math.max(0, x - y);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With