# output needs to be explained

Venkat Ramsimha

Ranch Hand

Posts: 127

posted 10 years ago

Which code determines the int value foo closest to a double value bar?

A. Int foo = (int) Math.max(bar);

B. Int foo = (int) Math.min(bar);

C. Int foo = (int) Math.abs(bar);

D. Int foo = (int) Math.ceil(bar);

E. Int foo = (int) Math.floor(bar);

F. Int foo = (int) Math.round(bar);

Answer: F

Hi All,

can anybody provide the explanation for the above?as how its possible?

thanks

venkat

A. Int foo = (int) Math.max(bar);

B. Int foo = (int) Math.min(bar);

C. Int foo = (int) Math.abs(bar);

D. Int foo = (int) Math.ceil(bar);

E. Int foo = (int) Math.floor(bar);

F. Int foo = (int) Math.round(bar);

Answer: F

Hi All,

can anybody provide the explanation for the above?as how its possible?

thanks

venkat

Kumar J

Ranch Hand

Posts: 35

posted 10 years ago

Refer to this...

max(double a, double b)

Returns the greater of two double values.

min(double a, double b)

Returns the smaller of two double values

abs(float a)

Returns the absolute value of a float value.

ceil(double a)

Returns the smallest (closest to negative infinity) double value that is not less than the argument and is equal to a mathematical integer.

floor(double a)

Returns the largest (closest to positive infinity) double value that is not greater than the argument and is equal to a mathematical integer.

round(double a)

Returns the closest long to the argument.

straight from the API.

Now let us take 24.4354321333

what will max(),min(),abs(),ceil(),and floor() of this number?

max(double a, double b)

Returns the greater of two double values.

min(double a, double b)

Returns the smaller of two double values

abs(float a)

Returns the absolute value of a float value.

ceil(double a)

Returns the smallest (closest to negative infinity) double value that is not less than the argument and is equal to a mathematical integer.

floor(double a)

Returns the largest (closest to positive infinity) double value that is not greater than the argument and is equal to a mathematical integer.

round(double a)

Returns the closest long to the argument.

straight from the API.

Now let us take 24.4354321333

what will max(),min(),abs(),ceil(),and floor() of this number?

With Regards,<br />Kumar J

Barry Gaunt

Ranch Hand

Posts: 7729

posted 10 years ago

"Mr Kumar J" (aka Mr Kumar V) please change your displayed name to conform to our JavaRanch Naming Policy. In short: No "Mr", and a displayed name in the format <first name> <family name>. You may use initials only in place of your first name. You can change your displayed name via the "My Profile" link.

Thanks

-Barry

(NR)

Thanks

-Barry

(NR)

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch

Getting someone to think and try something out is much more useful than just telling them the answer.

Kumar J

Ranch Hand

Posts: 35

posted 10 years ago

Hi Barry,

Thanks for bringing to my notice.

I think you have not mentioned in the Naming Policy that we should not use Mr/Dr/Sir.I think it would be nice to put it.Next V is for Varma that we put as initial.Is it essential to put the initial in the beginning ? J meant Java/JCP.Let me know if this is ok.Thank you.

[ May 12, 2005: Message edited by: Kumar J ]

Thanks for bringing to my notice.

I think you have not mentioned in the Naming Policy that we should not use Mr/Dr/Sir.I think it would be nice to put it.Next V is for Varma that we put as initial.Is it essential to put the initial in the beginning ? J meant Java/JCP.Let me know if this is ok.Thank you.

[ May 12, 2005: Message edited by: Kumar J ]

With Regards,<br />Kumar J