0 votes
1 view
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
by (46.1k 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;

Related questions

0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...