import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Hanoi {
public void move(int n,char a,char b,char c){
if(n==1){
System.out.println("盘"+n+" 从"+a+"移至"+c);
}else{/*A-->B,A-->C,B--C*/
move(n-1,a,c,b);
System.out.println("盘"+n+" 从"+a+"移至"+c);
move(n-1,b,a,c);
}
}
public static void main(String[] args) throws NumberFormatException, IOException{
BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入盘的个数N=");
int n = Integer.parseInt(buf.readLine());
new Hanoi().move(n, 'A', 'B', 'C');
}
}
import java.io.IOException;
import java.io.InputStreamReader;
public class Hanoi {
public void move(int n,char a,char b,char c){
if(n==1){
System.out.println("盘"+n+" 从"+a+"移至"+c);
}else{/*A-->B,A-->C,B--C*/
move(n-1,a,c,b);
System.out.println("盘"+n+" 从"+a+"移至"+c);
move(n-1,b,a,c);
}
}
public static void main(String[] args) throws NumberFormatException, IOException{
BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入盘的个数N=");
int n = Integer.parseInt(buf.readLine());
new Hanoi().move(n, 'A', 'B', 'C');
}
}