What is the output { 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 ///why? c) Infinity -Infinity Infinity d) 4.4E99 -4.4E99 4.4E99 Correct answer is b)
Doubt: how is it working for Double and not Float?
This is because of the range of float. The largest positive finite float literal is 3.4028235e38f. The smallest positive finite nonzero literal of type float is 1.40e-45f.
You will get a compiler error if you use a float literal out of the specified range like the following code
It does not work as you expect for Float because the maximum value that you can store in a Float is approximately 3.4e38, and 4.4e99 is larger than that.
The range for Double is larger (the max. is approx. 1.8e308).
I did not think we are required to know the range of values each primitive type and their respective wrapper class can hold for the exam. Did this change? [ August 28, 2007: Message edited by: Chris Stann ]
This is because of the range of float. The largest positive finite float literal is 3.4028235e38f. The smallest positive finite nonzero literal of type float is 1.40e-45f.