How I can write the program with bitwise operators instead of if statements, which will interpret as coordinates on the number axis of end points of two intervals: A = [a1, a2] and B = [b1, b2]. The program reads from the user one number (say, x) of type int and prints whether it is true that
• x ∈ A
• x ∈ B
• x ∈ A \ B
• x ∈ B \ A
• x ∈ A ∩ B
• x ∈ A ∪ B
For example, if the defined intervals are A = [2, 4] and B = [1, 6] and the number read is x = 5, the program should print something like:
Interval A = [2, 4]
Interval B = [1, 6]
Enter x 5
x in A: false
x in B: true
x in A\B: false
x in B\A: true
x in intersection of A and B: false
x in union of A and B: true
So now this is what I have
import org.w3c.dom.ranges.Range;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("input a1");
int a1 = sc.nextInt();
System.out.println("input a2");
int a2 = sc.nextInt();
System.out.println("input b1");
int b1 = sc.nextInt();
System.out.println("input b2");
int b2 = sc.nextInt();
int a =a1&a2;
System.out.println("Interval A = " +a);
int b = b1 & b2;
System.out.println("Interval B = " + b);
System.out.println("input x");
int x = sc.nextInt();
System.out.println("Interval A = [" + a1 + "," + a2 + "]");
System.out.println("Interval B = [" + b1 + "," + b2 + "]");
System.out.println("Enter x " + x);
System.out.println("x in A: ");
System.out.println("x in B: ");
System.out.println("x in A/B: ");
System.out.println("x in B/A: ");
System.out.println("x in intersection of A and B: ");
System.out.println("x is union of A and B: ");
System.out.println("x in symm. diff. of A and B: ");
}
}