Welcome Guest | Sign in | Register
java.lang.class - Discussion Page For Q.2901 | Java Programming Questions and Answers | Java Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Home > Java Programming > java.lang.class > Questions and Answers

Exercise:

Section 1

Q: Which of the following will produce an answer that is closest in value to a double, d, while not being greater than d?
A. (int)Math.min(d); B. (int)Math.max(d);
C. (int)Math.abs(d); D. (int)Math.floor(d);

Answer and Explanation

Answer:(int)Math.floor(d);

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).

Comment on this Question

Name:

Loading...




Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.