This week's book giveaway is in the Spring forum.
We're giving away four copies of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 and have Marten Deinum & Iuliana Cosmina on-line!
See this thread for details.
Win a copy of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 this week in the Spring forum!
  • 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: 26614
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.
 
Life just hasn't been the same since the volcano erupted and now the air is full of tiny ads.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic