logo CodeStepByStep logo

IfElseMystery1

Language/Type: C# if/else

For each call to the following method, indicate what output is produced.

public static void Mystery(int n)
{
    Console.Write(n + " ");
    if (n > 0)
    {
        n = n - 5;
    }
    if (n < 0)
    {
        n = n + 7;
    }
    else
    {
        n = n * 2;
    }
    Console.WriteLine(n);
}
Mystery(8);
Mystery(-3);
Mystery(1);
Mystery(0);

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.