nick woodward wrote:I'm a bit confused as to why some of these assignments are allowed, if anyone minds straightening me out please!
nick woodward wrote:line 1: allowed as it's a binary representation of an integer literal widened to float
nick woodward wrote:line 2: binary can't represent float literals? (enthuware)
nick woodward wrote:line 3: hexadecimal can - so the f is a suffix, not a hexadecimal value?
nick woodward wrote:line 4: but this line makes me think it's a hexadecimal value - how can a float literal be assigned to an int implicitly?
Ramya Subraamanian wrote:I think line 2 doesnt work because, you cannot have values like' f' in a binary representation. you can have only 0 or 1.If you remove 'f' it should work.
...
and I think in line 3 and line 4,'f' must be hexadecimal value only.
Joe Bishara wrote:
Ramya Subraamanian wrote:...you can have only 0 or 1
Not quite right. An l or L suffix is allowed.
Not quite right. An l or L suffix is allowed.
Test 5, question 30
float x = 0b10_000f; This is invalid because the floating point suffices f, F or d, D are used only when using decimal system or hexadecimal and not while using binary.
nick woodward wrote:to me this suggests that the f as a suffix can be used with hexadecimals. but the answer is not distinguishing between being a suffix, and just being allowed at the end of the hex number as a normal value.
nick woodward wrote:however, from what you're saying Roel, it seems the distinction is when the literal being assigned is greater than the max range of an integer, and that this isn't possible with binary numbers, but is with others.
nick woodward wrote:do you see where my confusion came from in that enthuware answer though? it does seem to suggest that 'f' and 'd' can be used as a suffix in hex.
nick woodward wrote:yeah, it seems that i somehow got confused by the answer:
Test 5, question 30
float x = 0b10_000f; This is invalid because the floating point suffices f, F or d, D are used only when using decimal system or hexadecimal and not while using binary.
to me this suggests that the f as a suffix can be used with hexadecimals. but the answer is not distinguishing between being a suffix, and just being allowed at the end of the hex number as a normal value.
Nick
This is invalid because the floating point suffices ///f, F, d, and D/// are used only when using decimal system and not while using binary. However, since f is a valid digit in hexadecimal system, a hex number may end with an f although it will not be interpreted as float but as the digit f. Thus, float x = 0x10_000f; and float x = 10_000f; are valid because they are written in hex and decimal respectively but float x = 0b10_000f; is invalid because is written in binary.
Note that a floating point number cannot be written in Octal. Therefore, float x = 010_000f; is valid but it is not octal even though it starts with a 0. It is interpreted in decimal.
Enthuware - Best Mock Exams and Questions for Oracle Java Certifications
Quality Guaranteed - Pass or Full Refund!
Paul Anilprem wrote:
Note that a floating point number cannot be written in Octal. Therefore, float x = 010_000f; is valid but it is not octal even though it starts with a 0. It is interpreted in decimal.
However, since f is a valid digit in hexadecimal system, a hex number may end with an f although it will not be interpreted as float but as the digit f
Don't get me started about those stupid light bulbs. |