• 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

Math class

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
44. What method(s) from the java.lang.Math class might method() be if the statement

method( -4.4 ) == -4;

is true.

a) round()
b) min()
c) trunc()
d) abs()
e) floor()
f) ceil()
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
correct answers are:


1- Math.ceil( -4.4 ) == -4;
2- MAth.round(-4.4 ) == -4;



There are two overloaded versions of round, one takes float and returns int
and another takes double and returns long.



Regards,
cmbhatt
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you're preparing for the exam, I think the important question is: What steps did you take in trying to answer this question?

For this type of question, you should first attempt an answer based on what you already know. Your next stop should be the API documentation to research the methods listed as options. And finally, you should write test code to verify your understanding.

(Also, note that the Math class is included in the 1.4 exam, but not the 1.5 exam.)
 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Would go for round only
as ceil would give -4.0 and not -4

public static double ceil(double a)

oops didn't realize it was == , hmm ceil and round would be good
[ April 21, 2007: Message edited by: swarna dasa ]
 
All that thinking. Doesn't it hurt? What do you think about this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic