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

Doubt about OCA Self Test Chapter 1, Question 3 (K&B7)

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you please confirm if I am doing something wrong here, or if the answer for Self-Test question Chapter1, question 3 is wrong.
I tested the code for the class and got a different result:



My result was C (-A.)
The book's answer is B ( A. )
 
Ranch Hand
Posts: 241
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I get the same result as the book. The '-' never gets added to the String because of the post increment operator in the for loop.

Try running this:



Output:
 
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
Hi Jose Robles,

First of all, a warm welcome to CodeRanch!

Jose Robles wrote:Can you please confirm if I am doing something wrong here, or if the answer for Self-Test question Chapter1, question 3 is wrong.


I agree with T Vergilio: the study guide is spot-on! The code snippet you have posted looks exactly the same as in the study guide. You didn't have posted the complete java command which resulted in a different result, so it's very hard to tell what you did wrong. In this topic you'll find an excellent explanation about the exact same question (code snippet). I'm pretty sure after carefully reading this topic all your doubts (concerning this topic) will be cleared. If you still have doubts/questions after reading this topic, simply click on the "Post reply" button and let us know

Hope it helps!
Kind regards,
Roel
 
Jose Robles
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to all. I saw what was wrong now.
The first string after the "java" runtime program name is the class name, which happens to be "_", and is not passed as a command line argument into the __A_V_ array. The actual contents of the __A_V_[] array is:
__A_V_[0] = "-"
__A_V_[1] = "A"
__A_V_[2] = "."


Thank you!

 
Roel De Nijs
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

Jose Robles wrote:The first string after the "java" runtime program name is the class name, which happens to be "_", and is not passed as a command line argument into the __A_V_ array. The actual contents of the __A_V_[] array is:
__A_V_[0] = "-"
__A_V_[1] = "A"
__A_V_[2] = "."


You are spot-on!
 
reply
    Bookmark Topic Watch Topic
  • New Topic