logo CodeStepByStep logo

StarString

Language/Type: C# recursion

Write a recursive method named StarString that accepts an integer parameter n and returns a string of stars (asterisks) 2n long (i.e., 2 to the nth power). For example:

Call Returns Reason
StarString(0); "*" 20 = 1
StarString(1); "**" 21 = 2
StarString(2); "****" 22 = 4
StarString(3); "********" 23 = 8
StarString(4); "****************" 24 = 16

You should throw an ArgumentException if passed a value less than 0.

Method: Write a C# 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.