具有前导零的Int - 意外结果 [英] Int with leading zeroes - unexpected result
本文介绍了具有前导零的Int - 意外结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给出以下示例:
public class Main {
public static void main(String[] args) {
System.out.println(1234);
System.out.println(01234);
}
}
输出为:
1234
668
为什么?
推荐答案
这是因为带有前导零的整数文字是八进制整数(基数为8):
This is because integer literals with a leading zero are octal integers (base 8):
1 * 8^3 + 2 * 8^2 + 3 * 8 + 4 = 668
这篇关于具有前导零的Int - 意外结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文