Check if given number is even or odd using bitwise operator.
// if last bit is 0 its even, else its odd
public static boolean isEven(int num) {
int result = num & 1;
if (result == 0)
return true;
return false;
}
Негізгі бет Ғылым және технология Check if number is Even Odd using bitwise | Interview Questions | Java
Пікірлер