Java Int Array - the stored number is different from the specified

I ran into the strangest problem ever in Java.

When I do this:

int []s = new int [5];
s[0] = 026;
s[1] = 0011;
s[2] = 1001;
s[3] = 0026;
s[4] = 1101;

The numbers stored in the array, which are visible from the debug mode, are different, that is, the stored numbers are 22.9, 1001, 22, 1101. Can you give me some tips on what could be wrong with this?

+3
source share
4 answers

Integer literals starting with 0 are interpreted as being in octal .

+8
source

Literal bytes, shorts, integers and long values, starting with 0, are interpreted as octal

(byte, short, int long) , . - , ; 10 , 0 9. - 8, 0 7. - 16, 0 9 A F. , , , , - . , , . 0 , 0x .

+4

.

+2

.

0

Source: https://habr.com/ru/post/1794470/


All Articles