logo Practice-It logo


Language/Type: Java assertions
Author: Roy McElmurry (on 2010/12/28)

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 int antCrawl(int max) {
    Random rand = new Random();
    int height = 0;
    int falls = 0;

    // Point A
    while (height < max) {
        int r = rand.nextInt(4);

        // Point B
        if (r == 0 && height > 0) {
            // Point C
        } else {
            // Point D

    // Point E
    return falls;

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

falls == 0 height > 0 height < max
Point A
Point B
Point C
Point D
Point E

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.