Given this code snippet: double a = 14.9; double b = method(a); System.out.println(b);
If this snippet displays 15.0 in the standard output, what Math method(s) could method() have invoke? Select the one right answer.
a)ceil() and round() b)floor() and round() c)ceil() only d)floor() only e)round() only Answer a This a question in barry bones mock exam(q no 31) the answer is given as a .But i thgt the answer is c) and not a) because when ceil and round is used then the answer should me 15L and not 15.0.please explain.
The reason why the answer is 'a' is: The value is assigned to a double variable, therefore the long value of the round method (15L) will be automatically promoted to double (following the rules of widening conversion). Hope this helps. ------------------ Asma Zafar, Sun Certified Programmer for Java2 Platform
Asma Zafar,<BR>Sun Certified Programmer for Java2 Platform
I remember from RoundUp Quiz that Math.round(double) will return a long, Math.round(float) will return an int. However, I went and checked on the code in question and notice that the long return will implicitly be cast to double b.
Answer a will work in this case. Soo the winner is Asma ------------------ Percy Densmore -SCJP2 Die Hard Student [This message has been edited by Percy Densmore (edited September 08, 2001).]
Joined: Apr 11, 2001
Hi all, I am sorry I didn't see the line double b = method(a). The first option will work too. Vanitha.
Joined: Jul 24, 2001
Even i didnt notice the line double b=method(a); Anyway now my doubt is cleared with Asma's explanation.Thanx guys! Archana