Possible Duplicate:
Integer with leading zeroes
I’m very new to Java. I did this :
System.out.println(01111);
which prints 4680. Why it didnt print out 01111?
Thanks in advance.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you want to print out the string “01111” then put it in quotes. That’s how you specify a string of characters in Java.
There is no decimal number 01111, so trying to print out the decimal number 01111 can’t possibly work.
The reason you got 4680 is because, in Java source code, a leading zero before a numeric constant indicates that the number is specified in octal and numbers are printed out in decimal. 11110 octal = 4680 decimal. (You must have done
01110to get 4680,01111would have given you 585.)