logo CodeStepByStep logo

loopMysteryExam10

Language/Type: Java method basics % mystery while loops

Given the following method, write the output of each of the following calls:

public static void whileMystery(int x, int y) {
    int z = 0;
    while (x % y != 0) {
        x = x / y;
        z++;
        System.out.print(x + ", ");
    }

    System.out.println(z);
}
whileMystery(25, 2);
whileMystery(32, 4);
whileMystery(10345, 10);
whileMystery(63, 2);

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.