| preferred AP College board partner for AP classes
AP Computer Science A/Unit 4: Iteration
Start Practice TestPractice Test
About Exam
medium Solved by 8 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 % b is equal to one.

C

When a and b are both even.

D

When a and b are both odd.

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

Question Leaderboard

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

AI Tutor

How can I help?

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