Win a copy of Head First Android this week in the Android 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Chapter 8, self test question 3 driving me crazy (K&B7)

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Quoted from this post in the Errata for OCA/OCP Java SE 7 Programmer I & II Study Guide (K&B7) thread.

D Tom wrote:Chapter 8, self test question 3.

Which invocation(s) will produce the output: 0 2 4 8 ?

The correct answer in the self test answers is B which is java Quetico "\B" "^23 *$76 bc"

But when I tried this, I got 0 2 4 5 7 10.



So I think the answer should be E, none of the above.



This is driving me crazy.. I agree with you, and logically it should be that, BUT when i do it the book way, passing arguments from the terminal to the program, it gives me the book answer 0 2 4 8
Anybody please help!
 
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 Nikolai Polikurov,

First of all, a warm welcome to CodeRanch!

Nikolai Polikurov wrote:This is driving me crazy.. I agree with you, and logically it should be that, BUT when i do it the book way, passing arguments from the terminal to the program, it gives me the book answer 0 2 4 8
Anybody please help!


Can you share exactly what you did? Because when I tried I never got the book's answer.

This is the little program I used (which is exactly the same as in the study guide)And this is the output of all my command line statements

Hope it helps!
Kind regards,
Roel
 
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
Okay, finally this mistery is solved thanks to this post.

When you invoke java Quetico "\B" "^23 *$76 bc" on bash, the string "^23 *$76 bc" is actually translated into the string "^23 *6 bc" before it is passed to the program. $7 is taken to be a variable without a value assigned to it. And the program produces the expected output 0 2 4 8 (and thus B is the correct answer if you are using a unix/linux computer). On a Windows machine you have to execute the following statement on the command linejava Quetico "\B" "^23 *6 bc" to get the same output.

So the appropriate fix would be to get rid of $7 in each of the possible answers. If you do, you'll get the following results:
 
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