This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
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
posted
0
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
posted
0
Sorry. Got it.
bill bozeman
Ranch Hand
Joined: Jun 30, 2000
Posts: 1070
posted
0
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
posted
0
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
posted
0
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