Computer Program Reading Comprehension Project
U of T Computer Program Reading Comprehension Project
Boolean Fumbles
This program excerpt helps the user to make good use of boolean type.

Download files: BooleanFumbles.java
Areas: if statements.


BooleanFumbles.java
1boolean value;
2boolean flag = false;
3
4if (flag == true){
5  value = true;
6} else if (flag == false){
7  value = false;
8}


Question 1
Describe in English what this code is doing.
Solution

Question 2
Does flag == true change the value of flag?
Solution

Question 3
What will happen if we mistakenly write
if (flag == true); {
instead of
if (flag == true) {
in line 4?
Solution

Question 4
What would happen if we mistakenly write
if (flag = true)
rather than
if (flag == true)
in line 4?
Hints Solution

Question 5
Write a line of code that is equivalent to Line 4, but simpler.
Solution

Question 6
Is the code
else if (flag == false)
necessary?
Solution

Question 7
Is it necessary to have an if statement in this program excerpt?
Solution