Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

mistake in K/B test question ???

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello all,

I have read the chapter 4, and done the test, but there is one question (nr 8) that sais:


Place the fragments into the code to produce the output 33. Note, you must use each fragment
exactly once.

CODE:
class Incr {
public static void main(String[] args) {
Integer x = 7;
int y = 2;

x ___ ___;
___ ___ ___;
___ ___ ___;
___ ___ ___;
System.out.println(x);
}
}

FRAGMENTS:
y y y y y x x
-= *= *= *=

And the solution they gave is:

class Incr {
public static void main(String[] args) {
Integer x = 7;
int y = 2;
x *= x; // x = 49
y *= y; // y = 25
y *= y; // y = 625
x -= y; // x = -576
System.out.println(x);
}
}

I put as comments the rezults of the operation they gave in the book, and as you can see the result is not 33, as they want.
So, is the test question wrong, or are the fragments given wrong ?
What do you think ?

Thank you
 
Ranch Hand
Posts: 332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
y *= y; // is 4, not 25

I'd say question is good, it gives 33. The comments are wrong.
[ May 10, 2007: Message edited by: John Stone ]
 
camelia codarcea
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello John

Yes, you are right. I don't know why I had in mind that y = 5....my mistake

Thank you
 
I think he's gonna try to grab my monkey. Do we have a monkey outfit for this tiny ad?
The trailboss has a kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic