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

1 Expert Approved Answer
Step: 1 Unlock

public static String repeat String s int n if n 0 else if n 0 return else if n 1 r... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Building Java Programs A Back to Basics Approach Questions!