Limited access

Upgrade to access all content for this subject

Consider 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?

pickChars("sweater", 3) returns: "sar"
pickChars("celebration", 4) returns: "ceao"
pickChars("struggling", 2) returns: "rgln"
pickChars("gingerbread", 3) returns: "ggrd"
pickChars("carton", 5) returns: "o"
Select an assignment template