logo CodeStepByStep logo

loopMysteryExam1

Language/Type: Java 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;
        System.out.print(i + " " + j + " ");
    }
    System.out.println(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?

If you do not understand how to solve an exercise or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect tests, etc.), please

Is there a problem? Contact a site administrator.

©, all rights reserved.