In PHP you can concatenate strings with .= so that the string grows with what ever you add to it. I wonder if this could be done in java? I made some test in this code, to add all number into one long string, but not working! Could it be done in some other way?
int number = 100;
for (int x = number; x <= 2; x--) {
resultat = resultat + Integer.toString(x);
}
Yes,
+=in Java is.=in PHP:result += Integer.toString(x). You just need to defineString resultat = ""above the loop. (And as others noted – fix your loop condition, it’s always false)However, in loops you’d better use a
StringBuilder. A String is immutable, so every time you use+a new string is created (which may be inefficient with bigger loops). Instead: