int i = 0;
int k = Integer.parseInt("12");
int j = k;
System.out.println(i+1 + " " + j+1);
Strangely the output received is
1 121
I can not figure out this basic difference. Please help me.
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.
Use brackets as follows
From the docs
Extending this to your scenario
it becomes
Since
iis an int so(i + 1) = 1, simple addition" "is aStringhence((i + 1) + " ")=1WITH SPACE (String concatenation)Similarly when
jand last1is added, its being added to aStringhenceStringconcatenation takes place, which justifies the output that you are getting.See