Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
medium Solved by 7 students

Loop Analysis With Integer Division

< Prev
Next >

Consider the following two methods.

/** Precondition: a > 0 and b > 0 */
public static int methodOne(int a, int b)
{
    int loopCount = 0;
    for (int i = 0; i < a / b; i++)
    {
        loopCount++;
    }
    return loopCount;
}

/** Precondition: a > 0 and b > 0 */
public static int methodTwo(int a, int b)
{
    int loopCount = 0;
    int i = 0;
    while (i < a)
    {
        loopCount++;
        i += b;
    }
    return loopCount;
}

Which of the following best describes the conditions under which methodOne and methodTwo return the same value?

A

When a % b is equal to zero.

B

When a and b are both odd.

C

When a and b are both even.

D

When a % b is equal to one.

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question
Mark for review

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Total Time
Score
#1hitrishabhatia12 0m 00s 90
#2sgarv251312 0m 00s 90
#3y.seong202711 1m 15s 25
#4yuvansankarnyc01 5m 40s -350
#5bommasam00012 24m 11s -1,361
#6Pelisx14 57m 38s -3,388
#7midnightasdark14 4h 17m -15,360
Items per page:
10
1 – 7 of 7
No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy|FAQ