アルゴリズム:ハノタ
853 ワード
public class $ {
public static void main(String... _) {
test('A', 'B', 'C', 3);
}
/**
* A, :B->C
*
* @param a
* A
* @param b
* B
* @param c
* C
* @param n
*
*/
private static void test(char a, char b, char c, int n) {
if (n == 1) {
move(b, c);
return;
}
test(c, b, a, n - 1);
move(b, c);
test(b, a, c, n - 1);
}
private static void move(char a, char b) {
System.out.println(a + "==>" + b);
}
}