Java 汉诺塔问题

package com.java.examples.digui;

public class Towers {
	public static void main(String[] args) {
		doTowers(2, 'A', 'B', 'C');
	}

	/**
	 * 
	 * @param topN how many disk
	 * @param from
	 * @param inner
	 * @param to
	 */
	public static void doTowers(int topN, char from, char inner, char to) {
		if (topN == 1) {
			System.out.println("Disk 1 from " + from + " to " + to);
		} else {
			doTowers(topN - 1, from, to, inner);
			System.out.println("Disk " + topN + " from " + from + " to " + to);
			doTowers(topN - 1, inner, from, to);
		}
	}
}

你可能感兴趣的:(java,C++,c,C#)