?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Moderate

Equivalent Methods Using a String Parameter

APCSA-ENWVTY

Consider the following methods.

public static int methodA(String str)
{
    return str.length();
}

public static int methodB(String str)
{
    int i = str.length();
    i = str.indexOf(str.substring(i-1));
    return i;
}

public static int methodC(String str)
{
    int a=0;
    for (int i=0; i<str.length();i++)
    {
        a++;
    }
    return a;
}

public static int methodD(String str)
{
    int a=0;
    for (int i=0; i<=str.length(); i++)
    {
        a++;
    }
    return a;
}

Which of these will return equivalent results (return the same value) when passed the same string parameter?

A

methodA and methodB have equivalent results.

B

methodB and methodC have equivalent results.

C

methodA and methodC have equivalent results.

D

methodA and methodD have equivalent results.

E

methodB and methodD have equivalent results.