?

AP® Computer Science Principles

Free Version

Upgrade subject to access all content

Easy

Documenting Procedures

APCSP-WVCWBJ

The following are descriptions of several procedures and code segments you will need for this question:

//text 
>adds the text as a comment; does not affect the code, only serves as documentation

x.charAt(i) 
>returns the character of the String x at index i

x.substring(a, b) 
>returns the substring of x from character a to character (b - 1)

x.length
>returns the length of the String x
Note that the index of the first character of a String is 0.

Consider the following procedure with one parameter (x):

PROCEDURE pro (x) {
    n ← x.length
    result ← ""
    REPEAT UNTIL (n = 0) {
        result ← result + x.charAt(n - 1)
        n ← n - 1
    }
    RETURN result
}

Which of the following comments would be helpful to document the procedure?

A

//returns the string backwards

B

//takes a string and returns the string backwards

C

//uses a while loop to reverse the parameter string

D

//reverses the string