In this task, you will use bitwise operators (&
, |
) along with if-else
statements to make decisions based on the results of the operations. The goal is to practice using bitwise operations and conditional logic in Java.
-
Input:
- Accept two integer inputs from the user.
-
Bitwise Operations:
- Perform the bitwise AND (
&
) operation on the two integers. - Perform the bitwise OR (
|
) operation on the two integers.
- Perform the bitwise AND (
-
Conditional Logic:
- If the result of the AND operation is greater than
10
, print"AND result is greater than 10"
. Otherwise, print"AND result is less than or equal to 10"
. - If the result of the OR operation is a multiple of
4
, print"OR result is a multiple of 4"
. Otherwise, print"OR result is not a multiple of 4"
.
- If the result of the AND operation is greater than
import java.util.Scanner;
public class BitwiseOperations {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Input values
System.out.print("Enter the first integer: ");
int num1 = scanner.nextInt();
System.out.print("Enter the second integer: ");
int num2 = scanner.nextInt();
// Bitwise Operations
//If else block for >10
//If else block for % 4
}
}