Primitive int value conversion?

public class Test3 {

    public static void main(String[] args) {
        int i = 010;
        System.out.println(i); // prints 8          


How come it prints 8? How is it getting converted? Debugging the program didn’t help.


010 is parsed as an octal number (as any number literal starting with 0). Its decimal value is 8. System.out.println prints the decimal value.

Leave a Reply

Your email address will not be published. Required fields are marked *