开发者

Java Int Array - Number being stored are different from ones specified

开发者 https://www.devze.com 2023-02-13 09:10 出处:网络
I have encountered the most weird problem ever in Java. When I am doing this: i开发者_开发知识库nt []s = new int [5];

I have encountered the most weird problem ever in Java.

When I am doing this:

i开发者_开发知识库nt []s = new int [5];
s[0] = 026;
s[1] = 0011;
s[2] = 1001;
s[3] = 0026;
s[4] = 1101;

The numbers being stored in the array, seen from debug mode, are different i.e. the numbers stored are 22,9,1001,22,1101. Can you give me some hints what might be wrong with this?


Integer literals that start with 0 are interpreted as being in octal format.


Literal bytes, shorts, integers and longs starting with 0 are interpreted as being octal

The integral types (byte, short, int, and long) can be expressed using decimal, octal, or hexadecimal number systems. Decimal is the number system you already use every day; it's based on 10 digits, numbered 0 through 9. The octal number system is base 8, consisting of the digits 0 through 7. The hexadecimal system is base 16, whose digits are the numbers 0 through 9 and the letters A through F. For general-purpose programming, the decimal system is likely to be the only number system you'll ever use. However, if you need octal or hexadecimal, the following example shows the correct syntax. The prefix 0 indicates octal, whereas 0x indicates hexadecimal.

from Primitive Data Types


The numbers with leading zeros are read as octal.


Numbers with leading zeros are termed as octal.

0

精彩评论

暂无评论...
验证码 换一张
取 消