0

I'm a new Java learner and I can't figure out why the result is different when using logical OR operator instead of bitwise OR o

I have searched it and all I could know is that | represents or as byte and || is the shorter, but I can't figure out how it is working in each step and why. I would really appreciate it if you could explain it to me from your experience! Here is the example which I tried to analyze and understand public class Main { public static void main(String[] args){ int a = 3; int b = 4; if ((a < b) || (++ a == b)) { System . out. println ("a = " + a); System . out. println ("b = " + b); } if ((a < b) | (++ a == b)) { System . out. println ("a != " + a); System . out. println ("b = " + b); } } } ::: First if statement result ::: a = 3 b = 4 ::: Second if statement result ::: a != 4 b = 4

29th Apr 2020, 10:27 AM
Mohammad Ala Tahhan
Mohammad Ala Tahhan - avatar
2 Respuestas