I was wondering if there's a way to do use String::concat with loops, instead of using StringBuilder/StringBuffer.
I tried it like this, but it doesn't work. Could someone help fix up the problem? or give me suggestions so I try it myself?
public class multiConcat {
public static void main(String[] args) {
int num = 0;
String finish = "";
Scanner reader = new Scanner(System.in);
System.out.println("Type a word: ");
String state = reader.next();
System.out.println("Number of Concatenation: ");
num = reader.nextInt();
finish = state.concat(state);
for (int i = 0; i == num; i++) {
finish.concat(state);
}
System.out.println(finish);
}
}
I thought it would be sthe ame idea as x = x + 1, i.e. constantly overwriting the value...
Thank you
you mean as this?
for (int i = 0; i == num; i++) {
finish = finish.concat(state);
}
finish = finish.concat(state);. and remove this linefinish = state.concat(state);