你怎么称呼这种赋值:float aFloat = 4.f;

dom*_*ri7 0 java numerical types

我想知道你怎么称呼它,我想到了"隐式数据类型",但似乎这真的不是我想象的.

我也想知道Java中的所有可能性,就像我知道你可以为其他数值做这些,比如字节,整数,长整数等.我自己搜索,但我仍然不知道如何定义这个一种数值变量赋值,或者如何命名它.

我对此很好奇,但我还是真的想知道!

提前致谢.

hay*_*lem 5

显式数字/数字文字

在你的例子中,它实际上不是"隐含的".恰恰相反.

这里有更多关于原始类型及其符号(下面粘贴的示例)来自官方Java教程,以及一些关于浮点数需要了解的技巧.

您可能还想了解有关转化,促销和窄播的更多信息.

例子:

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;
Run Code Online (Sandbox Code Playgroud)

使用下划线(自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;
Run Code Online (Sandbox Code Playgroud)