Limited access

Upgrade to access all content for this subject

Consider the following method with missing code.

public static int sumNums(int a, int b) 
{
    int c = 0;
    while (a <= b)
    {
        // missing code
    }
    return c;
}

Which of the following segments of code should replace // missing code in the sumNums method so that it returns the sum of the integers between a and b, both included?

For example, if a is 1 and b is 3, then the method should return 6, since 1+ 2+ 3 = 6.

A
c+=b;
a++;
B
c+=a;
a++;
C
c+=a;
b--;
D
c+=a;
b++;
E
a+=c;
c++;
Select an assignment template