开发者

How do you call this kind of assignment : float aFloat = 4.f;

I am trying to figure how do you call this, I thought of "implicit datatypes" but it seems this really isn't what I imagined.

I a开发者_C百科lso want to know all of the possibilities in Java, like I know you can do it for other numerical values, like bytes, integers, longs, etc. I'd search by myself but I still don't know how to define this sort of numerical variable assignment, or how to name it.

I was just curious about this but I still really want to know!

Thanks in advance.


Explicit Numerals / Numeric Literals

In your example, it's really not "implicit". Quite the reverse.

Here's more on primitive types and their notations (examples pasted below) from the official Java Tutorials, and some tricks you need to know about floats.

You may also want to learn more about conversions, promotions and narrow-casting.

Examples:

int    decVal = 26;      // The number 26, in decimal
int    octVal = 032;     // The number 26, in octal
int    hexVal = 0x1a;    // The number 26, in hexadecimal
int    binVal = 0b11010; // The number 26, in binary
double d1     = 123.4;
double d2     = 1.234e2; // same value as d1, but in scientific notation
float  f1     = 123.4f;

using underscores (since Java 7)

long  creditCardNumber     = 1234_5678_9012_3456L;
long  socialSecurityNumber = 999_99_9999L;
float pi                   = 3.14_15F;
long  hexBytes             = 0xFF_EC_DE_5E;
long  hexWords             = 0xCAFE_BABE;
long  maxLong              = 0x7fff_ffff_ffff_ffffL;
byte  nybbles              = 0b0010_0101;
long  bytes                = 0b11010010_01101001_10010100_10010010;


I agree with haylem, it is not implicit.

You asked for other numerical types examples:

Integer types:

073 (leading zero, octal)
123l (long)
0xFF (hex)

Floating point:

1.1E-3 (double)
1e10f (float)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜