Question: Write a recursive method called repeat that accepts a string and an integer as parameters and that returns concatenated together times. For example, repeat(hello, 3)
Write a recursive method called repeat that accepts a string and an integer as parameters and that returns concatenated together times. For example, repeat("hello", 3) returns "hellohellohello", and repeat( "ok", 1) returns "ok", and repeat( "bye", 0) returns "". String concatenation is an expensive operation, so for an added challenge try to solve this problem while performing fewer than concatenations.
Step by Step Solution
3.41 Rating (167 Votes )
There are 3 Steps involved in it
public static String repeat String s int n if n 0 else if n 0 return else if n 1 r... View full answer
Get step-by-step solutions from verified subject matter experts
