Skip to content

Commit a2bbd64

Browse files
myucesanjmrunkle
andauthored
Updating java/concepts/booleans/about.md (exercism#2042)
* Updating java/concepts/booleans/about.md Added some more examples explained the operators a little * Update concepts/booleans/about.md Co-authored-by: Jason Runkle <jmrunkle@gmail.com> Co-authored-by: Jason Runkle <jmrunkle@gmail.com>
1 parent 93e7779 commit a2bbd64

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

concepts/booleans/about.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,24 @@
22

33
Booleans in Java are represented by the `boolean` type, which values can be either `true` or `false`.
44

5-
Java supports three [boolean operators][operators]: `!` (NOT), `&&` (AND), and `||` (OR). The `&&` and `||` operators use _short-circuit evaluation_, which means that the right-hand side of the operator is only evaluated when needed.
5+
Java supports three [boolean operators][operators]:
6+
7+
- `!` (NOT): negates the boolean
8+
- `&&` (AND): takes two booleans and results in true if they're both true
9+
- `||` (OR): results in true if any of the two booleans is true
10+
11+
The `&&` and `||` operators use _short-circuit evaluation_, which means that the right-hand side of the operator is only evaluated when needed.
612

713
These are also known as conditional or logical operators. `!` is sometimes classified as a bitwise operation in the documentation but it has the conventional _NOT_ semantics.
814

915
```java
1016
true || false // => true
17+
false || false // => false
18+
false || true // => true
1119
true && false // => false
20+
true && true // => true
21+
!true // => false
22+
!false // => true
1223
```
1324

1425
The three boolean operators each have a different [_operator precedence_][precedence]. As a consequence, they are evaluated in this order: `not` first, `&&` second, and finally `||`. If you want to 'escape' these rules, you can enclose a boolean expression in parentheses (`()`), as the parentheses have an even higher operator precedence.

0 commit comments

Comments
 (0)