logo Practice-It logo

while loop mystery

Language/Type: Java method basics mod mystery while loops
Author: Marty Stepp (on 2020/04/15)

For each call below to the following method, write the value that is returned:

        public static void mystery(int x) {
            int y = 1;
            int z = 2;
            while (x > z) {
                if (x % z == 0) {
                    x = x / z;
                    y++;
                } else {
                    z++;
                }
            }
            System.out.println(y + " " + z);
        }
mystery(2);
mystery(5);
mystery(9);
mystery(12);

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.