Is there a grammar that provides mod in Java?

Asked 2 years ago, Updated 2 years ago, 24 views

I looked at the simple water code while solving the problem. I need to change the code below to Java I don't know the grammar that provides mod operations.

if ((a mod 2) == 0)
{
    isEven = true;
}
else
{
    isEven = false;
}

java modulo

2022-09-22 14:20

1 Answers

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.


2022-09-22 14:20

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.