posted 3 years ago
Chapter 2, Question # 28: The code contains six pairs of curly braces. How many pairs can be removed without changing the behavior?
Since there is no termination condition or break statement inside the if-else block, the code runs but never ends.
The solution I think is to add "i++;" or "break;" to if and else blocks, respectively:
Now the curly braces of for (lines 3/14) and while (lines 4/13) are optional, while the braces of if-else (lines 5/8 & 8/12), switch (lines 15/17), and the main method (lines 1/18) are required.
If so, the answer to this question should be corrected correspondingly: there are two instead of three pairs of curly braces can be removed. That is, the correct answer is Option B instead of C.