Java Programming - Java.lang Class - Discussion

Discussion Forum : Java.lang Class - Pointing out the correct statements (Q.No. 3)
3.
Which of the following will produce an answer that is closest in value to a double, d, while not being greater than d?
(int)Math.min(d);
(int)Math.max(d);
(int)Math.abs(d);
(int)Math.floor(d);
Answer: Option
Explanation:

The casting to an int is a smokescreen. Use a process of elimination to answer this question:

Option D is the correct answer, it is syntathecially correct and will consistently return a value less than d.

Option A and B are wrong because both the min() and max() methods require 2 arguments whereas here they are passed only one parameter.

Option C is wrong because it could return a value greater than d (if d was negative).

Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.