Check odd or even number in java without using modulus operator

Let’s learn check odd or even number in java without using modulus operator.

Check odd or even number in java without using modulus operator

Here’s how to find 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;
   }
}


Output:

104 is even number.