递归汉诺塔
public class HanoiQuestion {
private static void move(char from, char to) {
System.out.println("move the top plate from " + from + " to " + to);
}
public static void hanoi(char from, char to, char mid, int index) {
if (index == 1)
move(from, to);
else {
hanoi(from, mid, to, index - 1);
move(from, to);
hanoi(mid, to, from, index - 1);
}
}
public static void main(String[] args) {
HanoiQuestion.hanoi('A', 'B', 'C', 3);
}
}