?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Difficult

While Loop: Counts and Sums

APCSA-VETWJR

Consider the following method:

    public static int calcSum(int start, int increment, int end)
    {
         int sum=start;
         int count=0;
         while(sum<end)
         {
             sum+=increment;
             if  (sum%2==0)
             {
                 sum+=1;
                 count++;
             }
         }
         return sum;
    }

When calling this method as follows:

calcSum(10,9,40);

What will be the value of count and sum after the while loop completes its iteration?

A

sum = 40, count = 5

B

sum = 46, count = 3

C

sum = 46, count = 5

D

sum = 49, count = 3

E

sum = 49, count = 5