Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
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 (46k 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

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...