Check odd or even number in java without using modulus operator code example

Example: Check odd or even number in java without using modulus operator

// Check odd or even number in java without using modulus operator
public class EvenOddWithoutModulus
{
   public static void main(String[] args)
   {
      int number = 104;
      if(checkEvenNumber(number))
      {
         System.out.println(number + " is even number.");
      }
      else
      {
         System.out.println(number + "is odd number.");
      }
   }
   static boolean checkEvenNumber(int num)
   {
      boolean boolEven = true;
      for(int a = 1; a <= num; a++)
      {
         boolEven = !boolEven;
      }
      return boolEven;
   }
}

Tags:

Misc Example