How to Check If Number is Even or Odd without using Modulus or Remainder Operator

Write a Java program to find if a number is odd or even is one of the basic programming exercise, and anyone will be happy to see this in actual Java Interviews, wouldn't you? By the way did I said easy, well there is a little twist there, you need to check odd and even without using modulus (%) or remainder operator in Java. Since many programmers, especially freshers are familiar with % operator, this nice little trick does put them into thinking mode, which is what interviewer wants. This question is on similar level of checking if a number is palindrome or not, if you have practiced such questions, it would be easy to find solution. Any way, now, it's your turn to show off how good are you with different operators in Java and how quickly you can think of alternative solutions. Well, there are couple of ways to check if a number is even or odd without using modulus operator. First one is, by using division operator, and second method is by using bitwise operator in Java. An even number is an integer number is totally divisible by 2 i.e. when you divide even number by 2, remainder is zero. While  an odd number is an integer number, which is not multiple of two, if we divide odd number by 2, result would be fraction. If we focus on this definition, we always think about remainder operator, but we can still use division operator to check if number is even and odd, how? let's see.
Read more »

1 Response to "How to Check If Number is Even or Odd without using Modulus or Remainder Operator"

  1. Awesome!! You got the best article on this topic. You're doing a great job.

    Thanks for sharing.
    http://www.flowerbrackets.com/java-program-to-find-even-or-odd/

    BalasHapus