Advertisement
Vermiculus

Untitled

Feb 8th, 2012
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.38 KB | None | 0 0
  1. /**
  2.  * Expands a string s to have the length l
  3.  * @param s the String to expand
  4.  * @param l the length of the desired String
  5.  * @return s, copied until it has length l
  6.  */
  7. public static String expand(String s, int l) {
  8.     String ret = new String(s);
  9.    
  10.     while(ret.length() < l) {
  11.         ret += ret;
  12.     }
  13.    
  14.     if(ret.length() > l) {
  15.         ret = ret.substring(0, l);
  16.     }
  17.    
  18.     return ret;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement