Clarification about “int” number that begins with 0

后端 未结 4 1193
难免孤独
难免孤独 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:47

    012 is the octal value for 10 in decimal. So your telling java to print the integer at octal pos 012. Here: http://www.asciitable.com/ shows octal to decimal vaulue conversions.

提交回复
热议问题