Home
Goto Problem
Goto Problem
Given two strings, word and a separator, return a big string made of count occurences of the word, separated by the separator string.
repeatSeparator("Word", "X", 3) → "WordXWordXWord"
repeatSeparator("This", "And", 2) → "ThisAndThis"
repeatSeparator("This", "And", 1) → "This"
public String repeatSeparator(String word, String sep, int count)
{
String res=word;
if(count==0)
return "";
for(int i=1;i<count;i++)
{
res=res+sep;
res=res+word;
}
return res;
}
No comments:
Post a Comment