下划线在整数数据类型中不可见:
int intHex = 0x0041;
System.out.println("intHex: " + intHex);
int intBinary = 0b01000001;
System.out.println("intBinary: " + intBinary);
int intUnderscore = 1_23_456;
System.out.println("intUnderscore: " + intUnderscore);
答案 0 :(得分:5)
如果您希望
int intUnderscore = 1_23_456;
System.out.println("intUnderscore: " + intUnderscore);
打印
intUnderscore: 1_23_456
您误解了下划线的目的。它只是语法糖,旨在使源代码更易于阅读。