📅  最后修改于: 2020-10-13 05:27:56             🧑  作者: Mango
Java允许您在数字字面量使用下划线。此功能是Java 7中引入的。例如,该功能使您可以分隔数字字面量中的数字组,这可以提高源代码的可读性。
以下几点很重要:
public class UnderscoreInNumericLiteralExample {
public static void main(String[] args) {
// Underscore in integral literal
int a = 10_00000;
System.out.println("a = "+a);
// Underscore in floating literal
float b = 10.5_000f;
System.out.println("b = "+b);
// Underscore in binary literal
int c = 0B10_10;
System.out.println("c = "+c);
// Underscore in hexadecimal literal
int d = 0x1_1;
System.out.println("d = "+d);
// Underscore in octal literal
int e = 01_1;
System.out.println("e = "+e);
}
}
输出:
a = 1000000
b = 10.5
c = 10
d = 17
e = 9