Repeat a string: Difference between revisions

Line 18:
There's no function or operator to do this in Java, so you have to do it yourself.
<lang java5>public static String repeat(String str, int times){
StringBuilder ret = new StringBuilder(str);
for(int i = 10;i < times;i++) ret.append(str);
return ret.toString();
}
Line 26:
System.out.println(repeat("ha", 5));
}</lang>
 
=={{header|JavaScript}}==
This solution creates an array of n+1 null elements, then joins them using the target string as the delimiter
Anonymous user