aspose file tools*
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
Author

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");
System.out.println(f1);
System.out.println(f2);
System.out.println(d1);

a) Runtime error
b) Infinity
-Infinity
4.4E99
c) Infinity
-Infinity
Infinity
d) 4.4E99
-4.4E99
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
Greenhorn

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: 1533
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: http://aspose.com/file-tools
 
subject: Math Class