Find number is odd or even without % operator in java


In this core java programming tutorial we will write a program to Find number is odd or even without % operator in java.


Write a program to find number is odd or even without % operator in java.



LOGIC in java>
We will convert our decimal number into binary, binary number consists of only 0 and 1's ,
if its last digit is 1, then number is EVEN in java.
if its last digit is 0, then number is ODD in java.

Must read:   Binary to decimal conversion program in java.


Full Program/SourceCode / Example to Find number is odd or even without % operator in java >
/** Copyright (c), AnkitMittal www.JavaMadeSoEasy.com */
public class NumberIsOddOrEvenExample {
   public static void main(String[] args) {
         
          int number=53;
         
          if((number&1) ==0)
                 System.out.println(number+" is EVEN");
          else
                 System.out.println(number+" is ODD");
   }
}
/*OUTPUT
53 is ODD
*/


So, in this core java programming tutorial we wrote a program how to Find number is odd or even without % operator in java.

Previous program                                                                  Next program



Having any doubt? or you you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.




RELATED LINKS>



>Pattern/Pyramid generating program in java





No comments:

Post a Comment