Java Programming - Language Fundamentals - Discussion

Discussion Forum : Language Fundamentals - General Questions (Q.No. 12)
12.
Which three are valid declarations of a float?
  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;
1, 2, 4
2, 3, 5
1, 3, 6
2, 4, 6
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 2 of 4.

Sachin Shekhar said:   8 years ago
float f1 = -343;
float f3 = 0x12345;

How 1 &3 are float?

Please explain anyone. I am not able to get it.

Disha said:   1 decade ago
I also did not understand the same concept.

How do we find the range and find whether its double or float?.

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??

Shubham said:   9 years ago
Can anyone tell me?

Why 42e7 = 42*10^7?

Is not a float value as it range is less than 2^32?

ABC said:   1 decade ago
How can we decide value is float or double ? And why -343 is float?

Abi said:   1 decade ago
How the following declaration is correct in float?

float f1=-343;

Radhey said:   1 decade ago
How the following declaration is correct in float?

float f1=-343;

Vaibhavi said:   1 decade ago
oh.. thanks for explanation sundar..
i have read it somewhere...

Shalini Singh said:   1 decade ago
Please tell me how the following is correct ?

float f1 = -343;

Abcd said:   1 decade ago
How can we differentiate whether the value is float or double?


Post your comments here:

Your comments will be displayed after verification.