logo CodeStepByStep logo

RecursionMystery4

Language/Type: C# recursion

For each of the calls to the following recursive method below, indicate what output is produced:

public static void RecursionMystery4(int n)
{
    if (n <= 1)
    {
        Console.Write("*");
    }
    else if (n == 2)
    {
        RecursionMystery4(n - 1);
        Console.Write("*");
    }
    else
    {
        Console.Write("(");
        RecursionMystery4(n - 2);
        Console.Write(")");
    }
}
RecursionMystery4(2);
RecursionMystery4(3);
RecursionMystery4(4);
RecursionMystery4(6);
RecursionMystery4(9);

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.