Java Program to find whether a number is even or odd without using modulus/division operator.

Hey there!

Welcome to ClearUrDoubt.com.

In this post, we will look at a Java program to find whether a number is even or odd without using modulus/division operator.

Without using the Modulus/division operator, this can be achieved by using “bitwise AND” operator.

I would recommend you to go through the below post before you continue with this.

2’s complement – Binary representation of Negative numbers in Java

 

Logic: When a number is applied bitwise AND(“&“) with 1, if the LSB of the result is zero then the given number is Even else it is Odd.

 

Here is the Java program:

 

Output:

 

 

 

 

 

Happy Learning :).

Please leave a reply in case of any queries.

One Reply to “Java Program to find whether a number is even or odd without using modulus/division operator.”

Leave a Reply

Your email address will not be published.