• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Potential error for Sybex Practice Tests 11

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Marshal
Posts: 26601
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Miles Jiang wrote:Since there is no termination condition or break statement inside the if-else block, the code runs but never ends.



True.

The solution I think is to add "i++;" or "break;" to if and else blocks, respectively



The solution to what problem? The question asks you to remove pairs of curly braces while preserving the behaviour of the code. Yes, the behaviour includes never ending, but so what?
 
Miles Jiang
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmmm...tricky.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic