This is a beta version of Practice-It. Give us feedback

logo Practice-It logo

whileLoopMystery

Language/Type: Java method basics mystery while loops
Author: Stuart Reges (on 2020/10/06)

Consider the following method.

            public static void mystery(int y) {
                int x = 0;
                int z = 0;
                while (y > 0) {
                    x++;
                    z = z + y % 10;
                    y = y / 10;
                }
                System.out.println(x + " " + z);
            }
        

For each call below, indicate what output is produced.

mystery(8);
mystery(32);
mystery(184);
mystery(8239);

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.