+ 2

and logical operator

What does the and logical operator do?

5th Feb 2018, 9:20 PM
Anonymous
Anonymous - avatar
3 ответов
+ 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.
5th Feb 2018, 10:04 PM
John Wells
John Wells - avatar
+ 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”.
5th Feb 2018, 10:10 PM
Diwakar
Diwakar - avatar
+ 2
Thank you
6th Feb 2018, 12:37 AM
Anonymous
Anonymous - avatar