# 作为数据结构输入的填充零位

go评论44阅读模式

Padded zeroes as a part of an input for a data structure

# 问题

``````LinkedList<Integer> list = new LinkedList<>();

System.out.println(list.isEmpty());

System.out.println(list.get(1));

System.out.println(list.isEmpty());

for (Integer i: list) {
System.out.println(i);
}
``````

true
423
false
13
423
23
18
122
25

So I created a custom linkedlist and while testing it to ensure functionality, I noticed something weird.

When I run this code:

``````    LinkedList&lt;Integer&gt; list = new LinkedList&lt;&gt;();

System.out.println(list.isEmpty());

System.out.println(list.get(1));

System.out.println(list.isEmpty());

for (Integer i: list) {
System.out.println(i);
}
``````

I get this output:

true
423
false
13
423
23
18
122
25

Why is it that 022 got converted into 18?

# 答案1

022

= (2 * 8 ^ 0) + (2 * 8 ^ 1)
= (2 * 1) + (2 * 8)
= 2 + 16
= 18

Because it's taken as an octal base (8) since that numeral has 0 in leading. So, it's corresponding decimal value is 18.

022

``````= (2 * 8 ^ 0) + (2 * 8 ^ 1)
= (2 * 1) + (2 * 8)
=  2 + 16
=  18
``````

• 本文由 发表于 2020年7月30日 13:57:57
• 转载请务必保留本文链接：https://go.coder-hub.com/63167015.html
• java

go 51

go 52

go 55

go 46