programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Jeanne Boyarsky
• Ron McLeod
• Paul Clapham
• Liutauras Vilda
Sheriffs:
• paul wheaton
• Rob Spoor
• Devaka Cooray
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Carey Brown
• Frits Walraven
• Tim Moores
Bartenders:
• Mikalai Zaikin

# "valid declarations of a float" required

Ranch Hand
Posts: 70
• Number of slices to send:
Optional 'thank-you' note:
Which three are valid declarations of a float? (Choose Three)
A. Float foo = -1;
B. Float foo = 1.0;
C. Float foo = 42e1;
D. Float foo = 2.02f;
E. Float foo = 3.03d;
F. Float foo = 0x0123;
Answer: A, D, F
I think only D is right.
Do u follow me ??

Ranch Hand
Posts: 76
• Number of slices to send:
Optional 'thank-you' note:
If you make the "Float" words into "float" then its ok, but regarding your answer. All numbers that has a "." thingy on them or a decimal value (i think that is what is called) are initially considered as a double value.
For example declaring 1.2 means that you have a double 1.2 value.
With regards w/ the "-1" value. It means the you have an int value. Since it is implicitly castable to a float, or a float can hold an int value that statement is correct.

Remember the transition of numerical data types are as follows

byte -> short -> int -> long -> float -> double.

any backward assignment needs an explicit cast.
[ September 22, 2004: Message edited by: Doyle Matt ]

Sheriff
Posts: 7023
• Number of slices to send:
Optional 'thank-you' note:
Peter, you might like to take a look at section 3.10 Literals of the JLS.

 Don't get me started about those stupid light bulbs.
reply
Similar Threads