*
The moose likes Mock Exam Errata and the fly likes error in BB mock exam! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "error in BB mock exam!" Watch "error in BB mock exam!" New topic
Author

error in BB mock exam!

ego hu
Ranch Hand

Joined: Mar 20, 2001
Posts: 53
In Barry Boone's mock exam:
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

His answer is:
Question 32: a. Only ceil() & Round() will produce 15.0 from 14.9. The floor() method yields 14. (See chapter 10.)
In fact, Math.round() returns long type, so it will produce
15, but not 15.0.
I wrote a programme to check it. I think I am right.
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
You are right that round will produce an int or long, but since he says:
double b = ....
The result will get upcasted to a double, so 15.0 should print out.
Bill
ego hu
Ranch Hand

Joined: Mar 20, 2001
Posts: 53
Sorry.
Got it.
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
No problem. It is good that you remembered that round returns a long. I could never seem to remember what round, ceil, floor, and random returned.
Bill
Daniel Wu
Ranch Hand

Joined: Jun 13, 2001
Posts: 58
So Both a and c are right for both produce a printout of 15.0. Am i right?
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Daniel,
Both Math.round() and Math.ceil() will result in an output of 15.0 so only answer 'a' is correct. Answer 'c' say only ceil() will result in 15.0
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform


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

Joined: Jun 13, 2001
Posts: 58
Got you, Jane, thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: error in BB mock exam!