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 3 of 4.

Siddhesh said:   9 years ago
According to me, float f6 = 2.81F; is a valid declaration.

Asif Khan said:   7 years ago
f1=-343.

Because float ranges from 4.9e-324 to 3.4e+038.

Divya said:   1 decade ago
Hi guys.

How option 3 is correct can anyone explain it?

Rashmi upadhyay said:   1 decade ago
Hey please tell me. Why option 3 is declared as float?

Divya Prakash said:   7 years ago
How f1=-343 is float? Can anyone explain it please?
(2)

Sulemankhan said:   9 years ago
Why float f2=3.14 comes in double not under float?

Ranjith said:   8 years ago
@Sundar.

Super, your explanation was amazing!.

Bhanu Prasad said:   1 decade ago
float f2 = 3.14;

This is not float why ?

Kayu said:   1 decade ago
How can we say 42e7 as a double?

Raj said:   1 decade ago
Why 42e7 is not a float value?


Post your comments here:

Your comments will be displayed after verification.