HanioTower(java)

package javaBasic;

import java.util.Scanner;

public class HanioTower {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int level = sc.nextInt();
		move(level,'a','b','c');
	}
	
	static void move(int level,char from,char inter,char to) {
		if(level == 1) {
			System.out.println("1号盘子"+from+"-->"+to);
		}
		else {
			move(level-1,from,inter,to);
			System.out.println(level+"号盘子"+inter+"-->"+to);
			move(level-1,from,inter,to);
		}
	}
}

猜你喜欢

转载自blog.csdn.net/Moliay/article/details/84337074
今日推荐