Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUST

Repeat the given string exactly n times

// 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));
    }
}
 
PREVIOUS NEXT
Tagged: #Repeat #string #times
ADD COMMENT
Topic
Name
8+8 =