+ 2
and logical operator
What does the and logical operator do?
3 Answers
+ 10
Let's assume you have two varibles a and b. When they are both 0, you want to print 'zero'. When they are both 5, you want to print 'five'. In all other cases, you want to print the sum. You'd code:
if (a == 0 && b == 0)
System.out.println('zero');
else if (a == 5 && b == 5)
System.out.println('five');
else
System.out.println(a+b);
The && is your logical and. Both side's expressions must be true in order for the combined expression to be true. If a is 0 yet b isn't, you output the sum.
+ 4
1. Logical AND Operator
We can combine many relational expressions using âLogical Andâ operators .The result will be a boolean type.  This operator is represented by the symbol â&&â.Â
Consider the operation âoperand1 && operand2â
Here operand1 and operand2 can be relational expressions or boolean types. The result of the operation âoperand1 && operand2â will be
1. âtrueâ only if both operand1 and operand2 are âtrueâ
2. âfalseâ  if any of the operands (operand1 or operand2) is âfalseâ or both the operands (operand1 or operand2) are âfalseâ.
+ 2
Thank you