0

while doing practice java tests i came across this piece of code

  public class test {
  public static void main(String args[]) {
    int x,y;
    x = 3 & 5;
    y = 3 | 5;
    System.out.println(x + " " + y);

where x = 1 and y = 7. i understand that the & operator will evaluate both sides of an if statement as opposed to && evaluating left side first and then the right. (and the same thing for | and ||).
i dont understand how these operators are used in assignment like this. i know it has something to do with binary (i know what binary is) but how can bitwise AND and OR be used in assignments like this to produce these results?

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
user3527058
  • 23
  • 1
  • 5

0 Answers0