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
ScrambledStrings.java · scrambleWord()
■ Current line

Execution visualizer

while loop
Examples:
Original wordUnchanged input
New resultBuilt left to right
Current indexNext characterAlready processed
—
—
—
11
result""
Step 0 / 0Iterations: 0Swaps: 0Processed: 0
650 ms