Is 00 an integer or octal in Java?

拈花ヽ惹草 提交于 2019-11-26 11:36:22

问题


Is

00, 000, or 000...

an integer in Java? Or is it an octal? If is it an octal is

001 or 0005

an octal?


回答1:


All are integers, but...

1  is decimal
0  is decimal
01 is octal
00 is octal

From Java Language Specification (emphasis mine):

Note that octal numerals always consist of two or more digits; 0 is always considered to be a decimal numeral - not that it matters much in practice, for the numerals 0, 00, and 0x0 all represent exactly the same integer value.




回答2:


Number literal representation examples in Java will give you the answer:

int decimal = 100;
int octal = 0144;
int hex = 0x64;
int binary = 0b1100100;

So 00, 000 and 0000 are all octal(base-8) integers.




回答3:


Directly from specification

An octal numeral consists of an ASCII digit 0 followed by one or more of the ASCII digits 0 through 7 and can represent a positive, zero, or negative integer.

You can check 0 though 7



来源:https://stackoverflow.com/questions/24031843/is-00-an-integer-or-octal-in-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!