BiruLyu
9/18/2017 - 6:17 AM

HanoiTower.java

import java.util.Scanner;

public class HanoiTower {
	private static void move(String start, String end, int n) {
		System.out.println("Move the "+ n +"th disk from " + start + " to " + end);
	}
	private static void Hanoi(String A, String B, String C, int n) {
		if (n == 1) {
			move(A, C, n);
		} else {
			Hanoi(A, C, B, n - 1);
			move(A,C,n);
			Hanoi(B, A, C, n - 1);
		}
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		while(true) {
			System.out.println("Please input the number of disk need to be moved:");
			while (sc.hasNextLine()) {
				Hanoi("A", "B", "C", sc.nextInt());
			}
		}
		
	}

}