www.un.org/Depts/DGACM/index_spanish.htm 撰写 Java功能,这样,鉴于两条插图、字数和一个分离器,将一大计的计数归结,由分离人阵列。
repeatSeparator("Word", "X", 3) → "WordXWordXWord"
repeatSeparator("This", "And", 2) → "ThisAndThis"
repeatSeparator("This", "And", 1) → "This"
My code is as below but is not working
public String repeatSeparator(String word, String sep, int count) {
if(count == 1) {
return word;
}
if(count > 1) {
for (int i = 0; i < count-1; i++){
word = word + sep + word;
}
}
return word;
}
实例
Expected Run Result
repeatSeparator("Word", "X", 3) → "WordXWordXWord" "WordXWordXWordXWord" X