给定以下示例:
public class Main {
public static void main(String[] args) {
System.out.println(1234);
System.out.println(01234);
}
}
输出是:
1234
668
为什么?
最佳答案
这是因为带前导零的整数文字是八进制整数(以 8 为底):
1 * 8^3 + 2 * 8^2 + 3 * 8 + 4 = 668
关于java - 带前导零的 Int - 意外结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8254077/