废话不说上代码

import java.util.Scanner;

public class hannuota{
	
	public static void main(String args[]){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()) {
		int n=sc.nextInt();
		Hanio hanio = new Hanio();
		hanio.yidong(n, "A", "B", "C");
		System.out.println();
		}
	}
}
class Hanio{
	int i=1;
	public void print(int n, String A, String C){   
		System.out.println("第"+i+"步:"+n+"号盘从"+A+"柱移至"+C+"柱");
		i++;
	}
	public void yidong(int n, String A, String B, String C){
		if(n == 1){
			print(n,A,C);
		}else{
			yidong(n-1, A, C, B);
			print(n, A, C);    
			yidong(n-1, B, A, C);
	}
	}
}