???????????????????????????????????????ɡ?

??????????????

?????????????????????????????????????????????鶼???????????????????????????????????????

????(1)??????????????????1????? ??

????(2)????????????????1????n ?????????????????n-1????????????????????鷵????????????????μ??????

??????????

????[html] view plaincopyprint?

????import javax.swing.JOptionPane;

????/*

????* time:2012.12.2

????* author:??????

????* description:

????*/

????public class Hanoi {

????private final static String from = "????B";

????private final static String to = "????C";

????private final static String mid = "????A";

????public static void main(String[] args) {

????String input = JOptionPane.showInputDialog("????????????????????");

????int num = Integer.parseInt(input);

????Hanoi.move(num?? from?? mid?? to);

????}

????private static void move(int num?? String from2?? String mid2?? String to2) {

????if (num == 1) {

????System.out.println("???????1 ??" + from2 + "??" + to2);

????} else {

????move(num - 1?? from2?? to2?? mid2);

????System.out.println("???????" + num + " ??" + from2 + "??" + to2);

????move(num - 1?? mid2?? from2?? to2);

????}

????}

????}

????import javax.swing.JOptionPane;

????/*

????* time:2012.12.2

????* author:??????

????* description:

????*/

????public class Hanoi {

????private final static String from = "????B";

????private final static String to = "????C";

????private final static String mid = "????A";

????public static void main(String[] args) {

????String input = JOptionPane.showInputDialog("????????????????????");

????int num = Integer.parseInt(input);

????Hanoi.move(num?? from?? mid?? to);

????}

????private static void move(int num?? String from2?? String mid2?? String to2) {

????if (num == 1) {

????System.out.println("???????1 ??" + from2 + "??" + to2);

????} else {

????move(num - 1?? from2?? to2?? mid2);

????System.out.println("???????" + num + " ??" + from2 + "??" + to2);

????move(num - 1?? mid2?? from2?? to2);

????}

????}

????}