Clarification about “int” number that begins with 0

后端 未结 4 1190
难免孤独
难免孤独 2021-01-20 05:28
public class Test {

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

Why the output is : <

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-20 05:37

    Octal Number : Any number start with 0 is considered as an octal number (012) i.e. base-8 number system

    Simple octal number evaluation :

    1*8^1 + 2*8^0 = 10
    

    Octal Number

    For More information about Number System

提交回复
热议问题