• 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

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
 
Your mother is a hamster and your father smells of tiny ads!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic