+ 3
Single and Double Or and And Operators
What is the difference between | and || and ; & and &&
2 ответов
+ 3
+ 3
Though their function is same, there is a small difference in the way they are executed.
Incase of & operator,
It evaluates both sides of the operator ,while && evaluates the right side of the operator only if left side returns true.
Similarly,
The | evaluates both sides of the operator ,while || evaluates the right side of the operator only if left side returns false.
Example:
The output of the following line of code is 0,
int a =0,b=1;
if(a==1&--b>0)
System.out.println(b);
However, the out of the following code is 1,
int a=0,b=1;
if(a==1&&--b>0)
System.out.println(b);