Geddi - 3 years ago 128
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
`'F'`
is a
`char`
and that
`70L`
has the type
`long`
. Also, I know that
`0xf`
is hex(right?) and that
`070`
is octal. But what are those other numbers? And why the hell is
`77.7`
`double`
and not
`float`
as well?

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-1f`is 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