Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt about Self Test Chapter 5, Question 2 (CH5Q2, K&B7)

 
Georges VanH
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Chapter 5 | selftest 2






The command line : java HillTop eyra vafi draumur kara

Possible outputs:

Option A : EYRA VAFI DRAUMUR KARA
Option D : EYRA VAFI DRAUMUR KARA followed by a nullpointerexception (becaseuse the .toUppercase(); invocation for the 5th element throws a exception )

My answer : A
Books (correct) answer says : D

After testing and debugging the code with Eclipse (run configuration) no exceptions to report. the code works and prints out : EYRA VAFI DRAUMUR KARA
Answer A appears to be OK.

Thank you.

Rgds


 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

First of all, a warm welcome to CodeRanch!

After testing and debugging the code with Eclipse (run configuration) no exceptions to report. the code works and prints out : EYRA VAFI DRAUMUR KARA
Answer A appears to be OK.

Unfortunately your answer (A) is incorrect! The study guide is spot-on: answer D is correct!

It's of course really important if you run an application in your IDE to verify your answer, the code is exactly the same as in the study guide. Your code will indeed run without any exception (and A might seem to be the correct answer), but the code in the study guide is slightly different (but the difference is very important!)As you can see the print statement is not a part of the if statement. If you make this adjustment in your code, I'm pretty sure your code will throw a NullPointerException as well (and answer D is the correct one).

Hope it helps!
Kind regards,
Roel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic