?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Difficult

While Loop Iterating Through String

APCSA-LTID4E

Consider the following method.

public static String midString(String s)
{
    String output="";
    int b= 0, t = s.length()-1;
    while(b <= t)
    {
        output += s.substring(b,b+1);
        int m = (b+t) / 2;
        b = m + 1;
    }
    return output;
}

How many times would the body of the while loop execute when the following statement is executed:

midstring("responsibility");
A

3

B

4

C

5

D

6

E

7