File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Math Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Math Class" Watch "Math Class" New topic

Math Class

Richard Rex
Ranch Hand

Joined: Sep 19, 2005
Posts: 100
Hi to all ranchers,

While having a practice on one of the mock exams i got free over the net, I found this question confusing:

What will be the output of the code assuming embedded on a complete program.

Float f1 = new Float("4.4e99f");
Float f2 = new Float("-4.4e99f");
Double d1 = new Double("4.4e99");

a) Runtime error
b) Infinity
c) Infinity
d) 4.4E99

I answered D, but the correct answer says it's B. I also tried running this is my editor and it's really B. I looked for the answer explanation in the mock exam but unfortunately I got no explanation why.

Can somebody explain why the answer is B?

"If you fail to plan, you plan to fail."<br /> <br />Chad<br />SCJP 1.4<br />SCWCD 1.4<br />SCBCD 1.3<br />SCDJWS (next)
Gokul Somasundaram

Joined: Jul 17, 2005
Posts: 20
I hope the answer is simple. The float range is 3.4e-038 to 3.4 e+038. So e+99 is greeater than e+38. So the float value became infinite.
Richard Rex
Ranch Hand

Joined: Sep 19, 2005
Posts: 100
Hi Gokul Somasundaram,

Thanks a lot! Sorry I forget to consider the range. Now it's clear to me.
agrah upadhyay
Ranch Hand

Joined: Sep 01, 2005
Posts: 579
Ranges of float and double are xcluded from exam.I mean You won't find such questions.So Don't expect such brilliant question.
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1599
Thanks agrah! That is what even i was wondering about.

Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
I agree. Here's the link:
subject: Math Class
It's not a secret anymore!