汉诺塔游戏(Tower of Hanoi)

public class Hanio{
	public static void hanoi(int n,String start,String mid,String end){
		if(n==1){
			System.out.println(start+"--->"+end);
		}
		else{
			hanoi(n-1,start,end,mid);
			System.out.println(start+"--->"+end);
			hanoi(n-1,mid,start,end);
		}
	}
	public static void main(String[] args){
		hanoi(3,"A","B","C");
	}
}

你可能感兴趣的:(java学习笔记)