0 votes
1 view
ago in Java by (2.6k points)

As an example in pseudocode:

if ((a mod 2) == 0)

{

    isEven = true;

}

else

{

    isEven = false;

}

1 Answer

0 votes
ago by (26.5k points)

For non-negative integers, you can try the remainder operator %. For your exact instance:

if ((a % 2) == 0)

{

    isEven = true;

}

else

{

    isEven = false;

}

This can be modifed to a one-liner:

isEven = (a % 2) == 0;

...