1. Assuming that x is 1, show the result of the following Boolean expressions.
- (true) && (3 > 4)
- !(x > 0) && (x > 0)
- (x != 1) == !(x == 1)
- (x >= 0) || (x < 0)
2. List the precedence order of the Boolean operators. Evaluate the following expressions:
- 2 * 2 – 3 > 2 && 4 – 2 > 5
- 2 * 2 – 3 > 2 || 4 – 2 > 5
3. Is (x > 0 && x < 10) the same as ((x > 0) && (x < 10))? Is (x > 0 || x < 10 && y < 0) the same as (x > 0 || (x < 10 && y < 0))?
Jawaban :
1. Jawaban :
- Bagian kedua false dikarenakan 3 tidak lebih besar dari 4.
- False, bagian pertama benar, tetapi statement bagian kedua salah.
- True, statement pertama dan kedua benar.
- True, statement pertama dan kedua benar.
2. Jawaban :
- True, statement pertama dan kedua benar.
- True, statement pertama dan kedua benar.
3. Jawaban:
(x > 0 && x < 10) the same as ((x > 0) && (x < 10)) = statement ini menghasilkan nilai yang sama.
(x > 0 || x < 10 && y < 0) the same as (x > 0 || (x < 10 && y < 0)) = statement ini menghasilkan nilai yang sama juga.
Kedua-dua dari statement diatas dapat dijalankan.
Binus University – www.binus.ac.id