Повторите данную строку ровно n раз
// Repeat the given string exactly n times
public class Solution {
public static String repeatStr(final int repeat, final String string) {
String repeatedString = "";
for (int i = 0; i < repeat; i++) {
repeatedString += string;
}
return repeatedString;
}
}
import java.util.Collections;
public class Solution {
public static String repeatStr(final int repeat, final String string) {
return repeat < 0 ? "" : String.join("", Collections.nCopies(repeat, string));
}
}
Mackerel