验证中...
Languages: Java
Categories: 算法分析
Latest update 2019-11-08 21:00
hannuota.java
Raw Copy
public class Main {
public static void main(String[] args) {
hannota(3,"A","B","C");
}
public static void hannota(int n,String from , String middle, String end) {
if(n==1) {
System.out.println("把第1个盘子从:"+from+"移动到:"+end);
}else {
hannota(n-1, from , end, middle );
System.out.println("把第"+n+"个盘子从:"+from+"移动到:"+end);
hannota(n-1, middle , from, end );
}
}
}

Comment list( 0 )

Sign in for post a comment

Help Search