This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Boone Mock #32  RSS feed

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

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).]
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.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!