• 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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

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).]
 
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
Boost this thread!