package day0929;
import java.util.Scanner;
import java.util.prefs.BackingStoreException;
public class hanNuo {
private static int move;
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
System.out.println(“请输入盘子数”);
int n=sc.nextInt();
char A=‘A’;
char B=‘B’;
char C=‘C’;
move=0;
f(n,A,B,C);
System.out.println(“总次数”+move);
}
public static void f(int n,char A,char B,char C){
move++;
if(n==1){
System.out.println(“把第”+n+“盘子从”+A+“柱子移到”+C+“柱子”);
return ;
}
f(n-1,A,C,B);//A初始 C临时 B最终
System.out.println(“把第”+n+“盘子从”+A+“柱子移到”+C+“柱子”);
f(n-1,B,A,C);//B初始A临时C最终
}
}