Author Topic:   Math Class Methods
Alkesh Nandanwar
ranch hand
posted March 21, 2000 12:07 PM             
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()

I am not able to interprete the == sign here. a) is OK but f) is also given as right answer. will f) give -4 or -4.0?
Help me
Alkesh

Tony Alicea
sheriff
posted March 21, 2000 02:49 PM             
ceil() will yield ?4.0 and when you compare that to the int ?4, this int is converted to double. So the comparison gives true.

Nalini Mistry
ranch hand
posted March 22, 2000 08:55 AM             
"Java 2 the complete reference" : this book says that ceil() rounds UP to the closest int value and floor() rounds DOWN to the closest int value. so going by that ceil(-4.4) should return -5.0. The book even gives examples of numbers like 3.1 reurning 4.0 for the ceil() method. Someone please clarify??!!!!

SURYA
unregistered
posted March 22, 2000 09:11 AM           
Which one is greater -4 or -5 ?
I hope you got the answer by this time .If not read the topic once more

maha anna
bartender
posted March 22, 2000 11:34 AM             
Nalini,
Always this of this way. '+' is for credit. '-' is for debt . You are better off when the + Number is bigger and the - number is smaller right?
So +100 is always > +50
-50 is always > -100 // having lesser debt is always better than having larger debt right?

I know this is to silly to explain. But I don't want to disappoint people who post qstns naively.
regds
maha anna

Venkat Raman
greenhorn
posted March 23, 2000 12:58 PM         
Hi Nalini,
I think this simple rule to resolve ceil() and floor() should help.

This requires that you should be very familiar with round().

for all ceil(x) apply round(x+0.5)
for all floor(x) apply round(x-0.5);

Ofcourse, 8th grade maths teaches you to add and subtract with negative numbers as well.

|