Home
Goto Problem
Goto Problem
Given a string and an int N, return a string made of N repetitions of the last N characters of the string. You may assume that N is between 0 and the length of the string, inclusive.
repeatEnd("Hello", 3) → "llollollo"
repeatEnd("Hello", 2) → "lolo"
repeatEnd("Hello", 1) → "o"
public String repeatEnd(String str, int n) { String res=str.substring(str.length()-n); for(int i=1;i<n;i++) res=res+str.substring(str.length()-n); return res; }
No comments:
Post a Comment