logo CodeStepByStep logo

assertions1

Language/Type: Java assertions

You will identify various assertions as being either always true, never true or sometimes true/sometimes false at various points in program execution. The comments in the method below indicate the points of interest.

public static void mystery(int x, int y) {
    int z = 0;

    // Point A
    while (x != y) {
        // Point B
        z++;

        if (x > y) {
            // Point C
            x = x / 10;
        } else {
            // Point D
            y = y / 10;
        }
    }

    // Point E
    System.out.println(x + " " + y + " " + z);
}

Fill in each box of the the table below with ALWAYS, NEVER or SOMETIMES.

x > y z == 0 x == y
Point A
Point B
Point C
Point D
Point E

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.