+ 3

What is the difference between operands | and || in java?

30th Mar 2017, 6:33 PM
Анатолий Хайруллин
Анатолий Хайруллин - avatar
3 odpowiedzi
+ 17
|| is logical OR. It gives True if at least one of the conditions is true. example: (2<5 || 5==4 || 5%2==0) = true || false || false = true | is biwise OR. It converts the operands to equivalent binary numbers and checks bit by bit. At least one occurrence of 1 gives 1. example: (5 | 3 | 0) = 101 | 011 | 000 = 111 = 7
30th Mar 2017, 7:25 PM
Shamima Yasmin
Shamima Yasmin - avatar
+ 15
Here's a sample code :) Just trying out the new feature 😊 https://code.sololearn.com/cQDnUvsn2gU1/?ref=app
30th Mar 2017, 7:53 PM
Shamima Yasmin
Shamima Yasmin - avatar
+ 1
As far as i know || operator compares the expression to the left with the expression to the right and so does the | operator also. Difference is when the left side of the || operator is true then the right wird will not be compared but the | operator does.
30th Mar 2017, 7:42 PM
Thomas Zenglein
Thomas Zenglein - avatar