logo Practice-It logo

BJP5 Self-Check 5.20: whileLoopMystery3

Language/Type: Java if/else mystery while loops
Author: Leslie Ferguson (on 2019/09/19)

Given the following method:

public static int mystery(int x, int y) {
    while (x != 0 && y != 0) {
        if (x < y) {
            y = y - x;
        } else {
            x = x - y;
    return x + y;

Write the value returned by each of the following calls.

mystery(3, 3)
mystery(5, 3)
mystery(2, 6)
mystery(12, 18)
mystery(30, 75)

You must log in before you can solve this problem.

Log In

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

Is there a problem? Contact a site administrator.