Two Laptop Bag*
The moose likes Mock Exam Errata and the fly likes BB Question 32 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "BB Question 32" Watch "BB Question 32" New topic
Author

BB Question 32

Daniel Wu
Ranch Hand

Joined: Jun 13, 2001
Posts: 58
Question 32:
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

Author chooses a.
I think the answer should be c because the snippet displays a floating point number 15.0 rather than int or long 15. If round() is added as indicated by a , the display would be 15, not 15.0 anymore.
Am i right? Seek your confirmation or correction. Thanks a lot.

Jyotsna Umesh
Ranch Hand

Joined: May 09, 2001
Posts: 94
Yes, I agree with you. Answer should be C only.
Jyotsna
Daniel Wu
Ranch Hand

Joined: Jun 13, 2001
Posts: 58
Hi, refer to the previous topic, and it's helpful.
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
The correct answer is 'a'.
<code>Math.round(double)</code> returns a <code>long</code> however <code>b</code> has a declared type of <code>double</code> . The <code>long</code> value will be promoted to <code>double</code> and displayed as <code>15.0</code> not <code>15</code>.
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
[This message has been edited by Jane Griscti (edited June 17, 2001).]


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
Daniel Wu
Ranch Hand

Joined: Jun 13, 2001
Posts: 58
Originally posted by Jane Griscti:
The correct answer is 'a'.
<code>Math.round(double)</code> returns a <code>long</code> however <code>b</code> has a declared type of <code>double</code> . The <code>long</code> value will be promoted to <code>double</code> and displayed as <code>15.0</code> not <code>15</code>.
Hope that helps.

Jane, your explanation for option a is right.
How about option c "ceil()only"? I think it is right too. it produce 15.0 which is a double already. Thanks.
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Daniel,
Your kidding right! If we read the question you typed in your first post we see the instructions:
Select the one right answer
If a is the correct answer (as you stated to Jane), do you still think c is also an answer?
Always follow the instructions ... they are there to help you.
Regards,
Manfred.
Muhammad Farooq
Ranch Hand

Joined: May 08, 2001
Posts: 356
What I am seeing here is that "a" is the correct answer, as round() and ceil(), produce the same result i.e 15.0, if used individually.
--Farooq


Muhammad Farooq<br />Sun Certified Programmer for Java 2 Platform<br />Oracle8i Certified Professional Database Administrator
Amit Madan
Ranch Hand

Joined: Dec 20, 2000
Posts: 32
Hi
variable is of Double type so it convert 15 to 15.0 automaticaly
Amit
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: BB Question 32
 
Similar Threads
Boone
Boone Mock #32
Boone mock: Math.
Math Doubt
error in BB mock exam!