logo Practice-It logo

BJP5 Self-Check 5.3: whileLoopMystery1

Language/Type: Java basics mystery while loops
Author: Marty Stepp (on 2019/09/19)

Given the following method:

public static void mystery(int x) {
    int y = 1;
    int z = 0;
    while (2 * y <= x) {
        y = y * 2;
        z++;
    }
    System.out.println(y + " " + z);
}

Write the output of each of the following calls.

mystery(1);
mystery(6);
mystery(19);
mystery(39);
mystery(74);

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.