我們可以在數(shù)字字面量中的兩位數(shù)字之間使用下劃線。
例如,一個int文字2014可以寫成2_014,20_14,201_4。
允許以八進制,十六進制和二進制格式使用下劃線。
int下劃線大數(shù)字使得它們更容易閱讀。
以下示例顯示數(shù)字字面量中下劃線的有效用法:
int x1 = 2_014; // Underscore in deciaml format int x2 = 2___014; // Multiple consecutive underscores int x3 = 02_014; // Underscore in octal literal int x4 = 0b0111_1011_0001; // Underscore in binary literal int x5 = 0x7_B_1; // Underscores in hexadecimal literal byte b1 = 1_2_7; // Underscores in decimal format double d1 = 2_014.01_11; // Underscores in double literal
在數(shù)字字面量中只允許在數(shù)字之間使用下劃線。
更多建議: