Geddi Geddi - 1 year ago 64
Java Question

What are those numbers and what is their type?

Ok I got a couple values here:

'F', 0xf, 070, 70L, 77e-1f, 7.7f, 7.77e1, 77.7

I know that
is a
and that
has the type
. Also, I know that
is hex(right?) and that
is octal. But what are those other numbers? And why the hell is
and not
as well?

Answer Source

What you're looking for is this

  • About 77.7:

A floating-point literal is of type float if it ends with the letter F or f; otherwise its type is double and it can optionally end with the letter D or d.

  • 0xf is not of type hex. There is no type hex. It's simply an int wirtten in hex. Just like 070 is an int written in octal.

  • The literal 77e-1fis clearly a float since it ends with f.

  • The e is exponent i.e. 77e-1f is in fact 77 * 10^(-1) or 7.7. The literal 7.77e1 is a double for the same reason 77.7 is a double, it's just that 7.77e1 is equal to 7.77 * 10 ^ 1 = 77.7.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download