Java – subtract the smallest number from several numbers
•
Java
I have two numbers I want to subtract the lower number from the two values
x: 1000 y: 200 => result: x = 800 and y = 0.
The following is a little ugly for me, so is it better for me to do it?
if (x <= y) {
y = y - x;
x = 0
} else {
x = x - y;
y = 0;
}
Solution
This should be done:
int min = Math.min(x,y); x -= min; y -= min;
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
