logo CodeStepByStep logo

repeatString

Language/Type: Java recursion
Related Links:

Write a recursive method named repeatString that accepts a string and an integer n as parameters and that returns the string concatenated n times. For example, the call of repeatString("hello", 3) returns "hellohellohello". Do not use any loops; you must use recursion.

Constraints: Your method should throw an IllegalArgumentException if passed any negative value for n. You are not allowed to construct any structured objects other than Strings (no array, List, Scanner, etc.) and you may not use any loops to solve this problem; you must use recursion.

Method: Write a Java method as described, not a complete program or class.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.