Java – clarification of “int” numbers starting with 0

public class Test {
public class Test {

    public static void main(String[] args) {
        int i = 012;
        System.out.println(i);
    }
}

Why is the output: 10?

Solution

If a number starts from 0, it is an octal number with base 8 012 is a decimal 10

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>