aspose file tools*
The moose likes Mock Exam Errata and the fly likes Math Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "Math Doubt" Watch "Math Doubt" New topic
Author

Math Doubt

Archana Nair
Greenhorn

Joined: Jul 24, 2001
Posts: 13
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.
Asma Zafar
Ranch Hand

Joined: May 11, 2001
Posts: 49
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
Vanitha Sugumaran
Ranch Hand

Joined: Apr 11, 2001
Posts: 356
Hi,
I think ans c is correct since round () will return 15 not 15.0
Vanitha.
Percy Densmore
Ranch Hand

Joined: Mar 06, 2001
Posts: 214
Vanitha has a point there.

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).]
Vanitha Sugumaran
Ranch Hand

Joined: Apr 11, 2001
Posts: 356
Hi all,
I am sorry I didn't see the line double b = method(a).
The first option will work too.
Vanitha.
Archana Nair
Greenhorn

Joined: Jul 24, 2001
Posts: 13
Hi

Even i didnt notice the line double b=method(a);
Anyway now my doubt is cleared with Asma's explanation.Thanx guys!
Archana
PANDORA
Greenhorn

Joined: Jul 23, 2001
Posts: 5
Originally posted by Vanitha Sugumaran:
Hi all,
I am sorry I didn't see the line double b = method(a).
The first option will work too.
Vanitha.

I think so

wellcome to guobao.net<BR>[img]http://www.guobao.net/image/GBLOGO.jpg[/img] <BR>[url]http://www.guobao.net[url]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Math Doubt