• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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:
 
He was expelled for perverse baking experiments. This tiny ad is a model student:
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
    Bookmark Topic Watch Topic
  • New Topic