import java.util.Arrays;
import java.util.Stack;

public class Hanoi {

    Stack<Integer> sourcePeg = new Stack<Integer>();
    Stack<Integer> targetPeg = new Stack<Integer>();
    Stack<Integer> helperPeg = new Stack<Integer>();

    private void solve(int disks) {
        for (int i = disks; i > 0; i--) {
            sourcePeg.push(i);
        }
        System.out.println("Playing Hanoi for " + disks + " disks:\n");
        showPegs();
        move(disks, sourcePeg, targetPeg, helperPeg);
        System.out.println("Solved.");
    }

    private void move(int n, Stack<Integer> sourcePeg, Stack<Integer> targetPeg, Stack<Integer> helperPeg) {
        if (n > 0) {
            if (n > 1) {
                move(n - 1, sourcePeg, helperPeg, targetPeg);
            }
            targetPeg.push(sourcePeg.pop());
            showPegs();
            if (n > 1) {
                move(n - 1, helperPeg, targetPeg, sourcePeg);
            }
        }
    }

    private void showPegs() {
        System.out.println("sourcePeg = " + Arrays.toString(sourcePeg.toArray()));
        System.out.println("helperPeg = " + Arrays.toString(helperPeg.toArray()));
        System.out.println("targetPeg = " + Arrays.toString(targetPeg.toArray()) + "\n");
    }

    public static void main(String[] args) {
        Hanoi hanoi = new Hanoi();
        hanoi.solve(5);
    }
}

@@ -137,22 +137,22 @@
 nteger%3E 
-target
+helper
 Peg = ne
@@ -182,38 +182,38 @@
  Stack%3CInteger%3E 
-helper
+target
 Peg = new Stack%3C
@@ -234,121 +234,142 @@
    p
-rivate void solve(int disks) %7B%0A        for (int i = disks; i %3E 0; i--) %7B%0A            sourcePeg.push(i);%0A        %7D
+ublic static void main(String%5B%5D args) %7B%0A        new Hanoi().solve(5);%0A    %7D%0A%0A    private void solve(int disks) %7B%0A        setUp(disks);
 %0A   
@@ -691,37 +691,8 @@
 ) %7B%0A
-            if (n %3E 1) %7B%0A    
     
@@ -741,38 +741,24 @@
 targetPeg);%0A
-            %7D%0A
             
@@ -818,37 +818,8 @@
 ();%0A
-            if (n %3E 1) %7B%0A    
     
@@ -876,22 +876,8 @@
 g);%0A
-            %7D%0A
     
@@ -1191,111 +1191,126 @@
    p
-ublic static void main(String%5B%5D args) %7B%0A        Hanoi hanoi = new Hanoi();%0A        hanoi.solve(5);
+rivate void setUp(int disks) %7B%0A        for (int i = disks; i %3E 0; i--) %7B%0A            sourcePeg.push(i);%0A        %7D
 %0A    %7D%0A%7D
 %0A
@@ -1308,9 +1308,8 @@
 %0A    %7D%0A%7D
-%0A

tidy things up