and logical operator | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 2

and logical operator

What does the and logical operator do?

5th Feb 2018, 9:20 PM
Anonymous
Anonymous - avatar
3 Respostas
+ 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