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.
Radhey said:
1 decade ago
How the following declaration is correct in float?
float f1=-343;
float f1=-343;
Geet said:
1 decade ago
Why float 3.14 is not valid?
(1)
Divya said:
1 decade ago
Hi guys.
How option 3 is correct can anyone explain it?
How option 3 is correct can anyone explain it?
Soumya said:
1 decade ago
Is 42e7 not a float?
Queen said:
10 years ago
Like int = 23456.
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?
Why 42e7 = 42*10^7?
Is not a float value as it range is less than 2^32?
RAHUL CHARAN said:
9 years ago
Hi, @Shubham.
42e7 = 420000000.
Range of int = - 2147483648 to 2147483647 that means 42e7 < range of int, so we can put this value in int.
Now int x= 42e7;
If float f =x;
The rule is:
byte->short->int->long->float->double.
char->int.
Left to right is promotions are acceptable.
So, we can put int Val in float Val that's how it can be assigned to float even long value we can assign in float though long is of 8 bytes and float is 4 bytes but internal structures are different.
And e7 = 10^7;
It's exponential form.
42e7 = 420000000.
Range of int = - 2147483648 to 2147483647 that means 42e7 < range of int, so we can put this value in int.
Now int x= 42e7;
If float f =x;
The rule is:
byte->short->int->long->float->double.
char->int.
Left to right is promotions are acceptable.
So, we can put int Val in float Val that's how it can be assigned to float even long value we can assign in float though long is of 8 bytes and float is 4 bytes but internal structures are different.
And e7 = 10^7;
It's exponential form.
(1)
Siddhesh said:
9 years ago
According to me, float f6 = 2.81F; is a valid declaration.
Sulemankhan said:
9 years ago
Why float f2=3.14 comes in double not under float?
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.
float f3 = 0x12345;
How 1 &3 are float?
Please explain anyone. I am not able to get it.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers