?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Difficult

Pre-Conditions and Post-Conditions of a Method

APCSA-LKJTV4

Given the following code segment:

/**
* Given a string, return a string that is made up of every ith character
* @param i increment to select characters
* Precondition: s is not null
* Precondition: i > 0
* Postcondition: the returned string is made up of only the
* characters from the parameter string beginning with the character
* at position 0 and taking the characters at every ith position
*/
public static String pickChars(String s, int i)
{
     // implementation not shown
}

Which of the following would be an acceptable parameter and corresponding output from this method?

A
pickChars("sweater", 3) returns: "sar"
B
pickChars("celebration", 4) returns: "ceao"
C
pickChars("struggling", 2) returns: "rgln"
D
pickChars("gingerbread", 3) returns: "ggrd"
E
pickChars("carton", 5) returns: "o"