Complete the code to check if a number is even using bitwise AND.
boolean isEven = (num & [1]) == 0;
The least significant bit of an even number is 0. Using bitwise AND with 1 checks this bit.
Complete the code to print "Even" if number is even, else "Odd".
System.out.println((num & [1]) == 0 ? "Even" : "Odd");
Bitwise AND with 1 checks the last bit; 0 means even, 1 means odd.
Fix the error in the code to correctly check if number is odd.
boolean isOdd = (num [1] 1) == 1;
Bitwise AND (&) with 1 isolates the last bit to check oddness.
Fill both blanks to create a method that returns true if number is even.
public static boolean isEven(int num) {
return (num [1] 1) [2] 0;
}Use bitwise AND (&) to check last bit and compare with 0 using == to confirm evenness.
Fill both blanks to create a method that returns "Even" or "Odd" based on number.
public static String evenOrOdd(int num) {
return (num [1] 1) [2] 0 ? "Even" : "Odd";
}Use bitwise AND (&) with 1, compare with 0 using == to check evenness, then return "Even" or "Odd" accordingly.
