logo CodeStepByStep logo

LoopMysteryExam1

Language/Type: C# while return

For each call of the method below, write the output that is printed and the value that is returned:

public static int LoopMysteryExam1(int i, int j)
{
    while (i != 0 && j != 0)
    {
        i = i / j;
        j = (j - 1) / 2;
        Console.Write(i + " " + j + " ");
    }
    Console.WriteLine(i);
    return i + j;
}
LoopMysteryExam1(5, 0) output
LoopMysteryExam1(5, 0) return
LoopMysteryExam1(3, 2) output
LoopMysteryExam1(3, 2) return
LoopMysteryExam1(16, 5) output
LoopMysteryExam1(16, 5) return
LoopMysteryExam1(80, 9) output
LoopMysteryExam1(80, 9) return
LoopMysteryExam1(1600, 40) output
LoopMysteryExam1(1600, 40) return

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.