logo CodeStepByStep logo

Hogwarts

Language/Type: Java parameters return
Author: Mehran Sahami (on 2017/10/03)

For the following console program, trace through its execution by hand to write the three lines of output that are produced when it runs:

/*
 * File: Hogwarts.java
 * -------------------
 * This program is just testing your understanding of parameter passing.
 */
public class Hogwarts {
    public static void main(String[] args) {
        bludger(2001);
    }

    private static void bludger(int y) {
        int x = y / 1000;
        int z = (x + y);
        x = quaffle(z, y);
        println("bludger: x = " + x + ", y = " + y + ", z = " + z);
    }

    private static int quaffle(int x, int y) {
        int z = snitch(x + y, y);
        y /= z;
        println("quaffle: x = " + x + ", y = " + y + ", z = " + z);
        return z;
    }

    private static int snitch(int x, int y) {
        y = x / (x % 10);
        println("snitch: x = " + x + ", y = " + y);
        return y;
    }
}
line 1
line 2
line 3

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.