AP Computer Science A · Iteration
String Scramble Visualizer
Trace the Java solution and watch how the loop builds a new String.
2014 AP CSA FRQ · Q1(a)
AB→BA
The rule: scan left to right. When an A is immediately followed by a letter other than A, append the two letters in reverse order and skip both positions. Otherwise, keep the current letter.
Java solution
Line-by-line trace
■ Current line
Execution visualizer
while loopUse letters A–Z only. An empty string is also valid.
Examples:
Original
wordUnchanged inputNew
resultBuilt left to rightCurrent indexNext characterAlready processed
—
—
—
11
result""
Step 0 / 0Iterations: 0Swaps: 0Processed: 0