Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Nicole Hughes   on Apr 04 In Java Category.

  
Question Answered By: Casey Montgomery   on Apr 04

The simple way is to just check  the number  mod 2. If you get 1 it's
odd, otherwise even. The somewhat faster way on many systems
(although it probably won't matter unless you execute this code
millions of times in a loop) would be to check the bitwise and of the
number with 1. Again, if the result is 1 the number is odd,
otherwise even.

Share: 

 
 
Didn't find what you were looking for? Find more on how to check for odd or even? Or get search suggestion and latest updates.


Tagged: