concatenation output problem (toString Array) - java
Posted
by dowln
on Stack Overflow
See other posts from Stack Overflow
or by dowln
Published on 2010-06-11T16:09:51Z
Indexed on
2010/06/11
16:12 UTC
Read the original article
Hit count: 106
java
Hello,
I am trying to display the output as "1(10) 2(23) 3(29)" but instead getting output as "1 2 3 (10)(23)(29)". I would be grateful if someone could have a look the code and possible help me. I don't want to use arraylist.
the code this
// int[] Groups = {10, 23, 29}; in the constructor
public String toString()
{
String tempStringB = "";
String tempStringA = " ";
String tempStringC = " ";
for (int x = 1; x<=3; x+=1)
{
tempStringB = tempStringB + x + " ";
}
for(int i = 0; i < Group.length;i++)
{
tempStringA = tempStringA + "(" + Groups[i] + ")";
}
tempStringC = tempStringB + tempStringA;
return tempStringC;
}
© Stack Overflow or respective owner