• 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
  • Liutauras Vilda
  • Paul Clapham
  • paul wheaton
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Rob Spoor
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:

Mock explanations #14 of chapter 3 (Java OCA 8 Programmer I Study Guide)

 
Ranch Hand
Posts: 221
27
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

When I check my answers for review questions of chapter 3 I saw that my answer of #14 question is correct. But I look at explanation of this question I know that I think wrong in really. Because I forget one detail in this question. I remember substring don't change StringBuilder when I saw explanation. If option B returns "avaJ" I would choose it as correct answer. If we run this code we saw that option B returns "Java" so I didn't consider it as correct answer.
But explanation of #14 is written:

Option B is a nice distraction it does in fact return "avaJ". However, substring() returns a String, which is not stored anywhere.


Probably authors forget to put comment puzzle.reverse(); when run this code.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The answers given in the book are correct: A and C will print the required avaJ.

The explanation why B is wrong, is wrong itself If you would print the String returned by option B Java is indeed printed and not avaJ. Therefore it's definitely an incorrect answer (as mentioned in the book). But with the code as-is it's also not a nice distraction as the book suggests. To be a nice distraction option B should be replaced withWith this statement the explanation why B is wrong, would be correct.

And what about the last part of the eplanation of this question: and length() counts starting with 1? Does length() not start with 0? Although I understand what's meant here, I wonder if it would not be better (as in more obvious/clear) to just state that length() just returns the character count.

 
author & internet detective
Posts: 41763
887
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are both correct. Noted.
 
What's gotten into you? Could it be this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic