oop - Why is 1_2_3_4 a valid integer literal in java? -


why following work?

int a=1_2_3_4; system.out.println(a);   // 1234 

numeric literals specified in jls 3.10.1.

a decimal numeral either single ascii digit 0, representing integer zero, or consists of ascii digit 1 9 optionally followed 1 or more ascii digits 0 9 interspersed underscores, representing positive integer.

[...]

a hexadecimal numeral consists of leading ascii characters 0x or 0x followed 1 or more ascii hexadecimal digits interspersed underscores, , can represent positive, zero, or negative integer.

[...]

an octal numeral consists of ascii digit 0 followed 1 or more of ascii digits 0 through 7 interspersed underscores, , can represent positive, zero, or negative integer.

[...]

a binary numeral consists of leading ascii characters 0b or 0b followed 1 or more of ascii digits 0 or 1 interspersed underscores, , can represent positive, zero, or negative integer.

if you're asking why underscores don't have in groups of 3 digits decimal literals, different cultures group numbers differently - , hex , binary literals, depending on usage, want kinds of different obvious groupings.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -