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);
		}
	}
}

 

你可能感兴趣的:(java,算法,javaBasic)