Consider this code:
int x = 17;
int y = 013;
System.out.println("x+y = " + x + y);
When I run this code I get the output 1711. Can anybody tell me how do I get 1711?
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.
The
17is there directly.013is an octal constant equal to11in decimal.When added together after a string, they are concatenated as strings, not added as numbers.
I think what you want is:
or
Which will be a better result.