logo Practice-It logo


Language/Type: Java assertions
Author: Kimberly Todd (on 2010/12/28)

For the following method, identify each of the assertions in the table below as either being always true, never true, or sometimes true / sometimes false.

public static int threeHeads(Random rand) {
    int flip = 1;
    int heads = 0;
    int count = 0;

    // Point A
    while (heads < 3) {
        // Point B
        flip = rand.nextInt(2); // flip coin
        if (flip == 0) { // heads
            // Point C
        } else {
            // Point D
            heads = 0;
    // Point E
    return count;

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

flip == 0 heads == 0 flip > heads
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.