The operator to obtain the remainder in Java is %
. If you change the water supply code above to Java
if ((a % 2) == 0)
{
isEven = true;
}
else
{
isEven = false;
}
You can do it like this.
To make it simpler, isEven = (a%2) == 0;
can also be used.
© 2024 OneMinuteCode. All rights reserved.