Java Programming - Language Fundamentals - Discussion
Discussion Forum : Language Fundamentals - General Questions (Q.No. 12)
12.
Which three are valid declarations of a float?
- float f1 = -343;
- float f2 = 3.14;
- float f3 = 0x12345;
- float f4 = 42e7;
- float f5 = 2001.0D;
- float f6 = 2.81F;
Answer: Option
Explanation:
(1) and (3) are integer literals (32 bits), and integers can be legally assigned to floats (also 32 bits). (6) is correct because (F) is appended to the literal, declaring it as a float rather than a double (the default for floating point literals).
(2), (4),and (5) are all doubles.
Discussion:
36 comments Page 3 of 4.
Abi said:
1 decade ago
How the following declaration is correct in float?
float f1=-343;
float f1=-343;
Pratik said:
2 decades ago
if any decimal number which is in proper range
eg. float f=7.8
is possible,rite?
why not f=3.14??
eg. float f=7.8
is possible,rite?
why not f=3.14??
Shalini Singh said:
1 decade ago
Please tell me how the following is correct ?
float f1 = -343;
float f1 = -343;
Raj said:
1 decade ago
Why 42e7 is not a float value?
Pria said:
1 decade ago
A floating-point literal is of type float if it is suffixed with an ASCII letter F or f; otherwise its type is double.
ABC said:
1 decade ago
How can we decide value is float or double ? And why -343 is float?
Ankit said:
1 decade ago
By default java compiler takes any real number as a double, its on you and bit depend on the range of the numbers to declare it float. So to get more precise value java takes it double.
Abcd said:
1 decade ago
How can we differentiate whether the value is float or double?
Abc said:
1 decade ago
ox12345 is a hexadecimal number,its decimal form is 74565,which is within the range 2^32,may be so it's represented as float !
Rashmi upadhyay said:
1 decade ago
Hey please tell me. Why option 3 is declared as float?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers