Hello I want to string concatenate two numbers as in the code below:
tmp2 = Integer.toString(preresult) + tmp2.substring(2, tmp2.length());
Tmp2 is a string declared from before. Preresult is a integer that contains a number. If I print this line it adds the two values instead of string concatenation.
If I change Integer.toString(preresult) to for example Integer.toString(5) it string concatenates as I would like it to do. But having Integer.toString(preresult) it adds the two numbers instead of string concatenating.
The code for preresult :
preresult = Integer.parseInt(tmp2.substring(0, 1)) + Integer.parseInt(tmp2.substring(1, 2));
//It picks numbers from tmp2 and adds them together. If I print preresult it gives me a int (for example 9)
Once again please help me concatenate these two strings instead of adding them:
tmp2 = Integer.toString(preresult) + tmp2.substring(2, tmp2.length());
New to java please mercy :)
Integer.toString(preresult) + tmp2.substring(2, tmp2.length())will most certainly concatenateStrings and not sum numbers. Please provide a complete example that explains, what makes you think that there is arithmetics involved here.mainmethod you used for testing, including manySystem.out.printlncalls in order to print intermediate results and show us, which values thoseprintlncalls print out. That is something we could work with.println(tmp2);, before and after the "concatenation line"?mainmethod and that containsprintlncalls, what they print and what you expected them to print.