Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Boone Mock #32

 
Rolf Weasel
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is with reference to the Boone Mock dated March 5, 2000 located here

Question 32: Given this code snippet:

If this snippet displays 15.0 in the standard output, what Math method(s) could method() have invoke?
Select the one right answer.
a. ceil() and round()
b. floor() and round()
c. ceil() only
d. floor() only
e. round() only

Answer:
Question 32: c. Only ceil(). Round() will produce 15 from 14.9 not 15.0. The floor() method yields 14. (See chapter 10.)

In the code, the result of method() is assigned to the double b before printing. Hence, the result of round(a) will be promoted to 15.0. The answer should be (a).
[This message has been edited by Rolf Weasel (edited March 12, 2000).]
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Round does yield an int result however since it is assigned to a double (b), it is automatically cast to a double and the call to System.out.println(b) yields 15.0.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic