Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. Write a method named repl that accepts a String and a number of repetitions as parameters and returns the String concatenated that many times. For example, the call repl("hello", 3) returns "hellohellohello". If the number of repetitions is 0 or less, an empty string is returned.
  2.  
  3. --------Code--------
  4.  
  5. public String repl(String phrase, int num)
  6. {
  7. int i;
  8. String what = "";
  9.  
  10.  
  11. for(i = num-(num-1); i <= num; i++)
  12. {
  13. what += phrase;
  14. }
  15. return what;
  16. }
  17.  
  18. -------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement