A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Programmer Certification (SCJP/OCPJP)
Joined: May 12, 2005
Aug 12, 2005 14:23:00
Which three are valid declarations of a float? (Choose three.) 1. float f1 = -343; 2. float f2 = 3.14; 3. float f3 = 0x12345; 4. float f4 = 42e7; 5. float f5 = 2001.0D; 6. float f6 = 2.81F;
This is from K&B book. I don't know why option 4 '42e7' is a double. Can someone explain this? Thanks
SCJA, SCJP5.0, SCBCD, SCWCD
Joined: Aug 03, 2002
Aug 12, 2005 14:30:00
Because the "e7" means "10 to the power 7". So the number 47e7 means 42.0 times 10000000 or 420000000.0. The number 47e7 is therefore considered to be a literal double constant.
Ask a Meaningful Question
Getting someone to think and try something out is much more useful than just telling them the answer.
I agree. Here's the link:
subject: double type
Assignment to float
float and double range
See this question
Why is "float f4 = 42e7" not considered a valid declaration of a float in Java?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014