就是经典汉诺塔的问题
public class TestHanoi {
void Move(char chSour, char chDest) {
System.out.println("Move " + chSour + "-->" + chDest);
}
void Hanoi(int n, char chA, char chB, char chC) {
if (n == 1)
Move(chA, chC);
else {
Hanoi(n - 1, chA, chC, chB);
this.Move(chA, chC);
Hanoi(n - 1, chB, chA, chC);
}
}
public static void main(String[] args) {
int n = 6;
TestHanoi han = new TestHanoi();
han.Hanoi(n, 'A', 'B', 'C');
}
}