• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

error in BB mock exam!

 
ego hu
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1070
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry.
Got it.
 
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So Both a and c are right for both produce a printout of 15.0. Am i right?
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Daniel Wu
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got you, Jane, thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic