汉诺塔算法
package test;
import javax.swing.JOptionPane;
public class HanNuoTa {
private static final String DISK_B = "diskB";
private static final String DISK_A = "diskA";
private static final String DISK_C = "diskC";
static String from = DISK_A;
static String to = DISK_C;
static String mid = DISK_B;
public static void main(String args[]){
String input = JOptionPane.showInputDialog("请输入你的轮盘数量");
int num = Integer.parseInt(input);
move(num, from, mid, to);
}
private static void move (int num,String from2,String mid2,String to2){
if(num == 1){
System.out.println("move disk 1 from "+from2+" to "+to2);
}else{
move(num -1,from2,to2,mid2);
System.out.println("move disk "+num+" from "+from2+" to "+to2);
move(num-1,mid2,from2,to2);
}
}
}