yogesh kumar


{ City } delhi
< Country > india
* Profession * software developer
User No # 112907
Total Questions Posted # 0
Total Answers Posted # 1

Total Answers Posted for My Questions # 0
Total Views for My Questions # 0

Users Marked my Answers as Correct # 0
Users Marked my Answers as Wrong # 1
Questions / { yogesh kumar }
Questions Answers Category Views Company eMail




Answers / { yogesh kumar }

Question { IBM, 26150 }

To find whether a number is even or odd without using any
conditional operator??


Answer

Check given number is even or odd without using modulo operator.
for this we use & operator.
if any number is odd it must have right most bit 1.
example:
int i=5;
binary form i= 0101
now use & operator
int j=i&1;[0101&1]//
here j have 0001;

public class EvenandOddNumber {
public static void main(String[] args) {
int i=5;
int j=i&1;
if(j>0){
System.out.println("odd");
}
else {
System.out.println("even");
}
}
}

Is This Answer Correct ?    0 Yes 1 No