AP CSA FRQ Guide
2016 FRQ 4: StringFormatter
Calculate word lengths and gap sizes, then format a list of words into a line with distributed spaces.
List Formatting and String Building22 minute targetArrayListStringformattinginteger division
Skills Tested
What this FRQ is really practicing
ArrayListStringformattinginteger division
Treat these skills as the study checklist. If any tag feels shaky, review that topic before attempting the full written response.
Starter Approach
How to begin without copying a solution
- 1Sum word lengths.
- 2Compute base spaces between words using integer division.
- 3Build the formatted result and distribute leftover spaces from left to right.
Write a first attempt before revealing any solution outline. Most AP CSA FRQ progress comes from tracing your own code and finding the missing case.
Common Mistakes
Mistakes to watch for while writing
Using wordList.size() instead of wordList.size() - 1 for gaps.
Adding a trailing gap after the final word.
Forgetting to distribute leftover spaces.
Self Check
Review questions before you submit
Sums the length of every word.
Use word.length() for each item in the list.
Divides extra spaces by the number of gaps.
There is one fewer gap than there are words.
Builds and returns a formatted String.
Repeated concatenation or a StringBuilder can work.
Handles leftover spaces beyond the basic gap width.
The earliest gaps receive the extra spaces.
Practice Links
