package com;
import java.util.Scanner;
public class HanoiY
{
void Move(char chSour,char chDest){
System.out.println("Move the top plate of "+chSour+"-->"+chDest);
}
void Hanoi(int n,char chA,char chB,char chC)
{
if(n==1)
Move(chA,chC);
else
{
Hanoi(n-1,chA,chC,chB);
this.Move(chA,chC);
Hanoi(n-1,chB,chA,chC);
}
}
public static void main(String[] args)
{
Scanner ss = new Scanner(System.in);
System.out.print("输入塔数:");
int n = ss.nextInt();
HanoiY han=new HanoiY();
han.Hanoi(n,'A','B','C');
}
}
import java.util.Scanner;
public class HanoiY
{
void Move(char chSour,char chDest){
System.out.println("Move the top plate of "+chSour+"-->"+chDest);
}
void Hanoi(int n,char chA,char chB,char chC)
{
if(n==1)
Move(chA,chC);
else
{
Hanoi(n-1,chA,chC,chB);
this.Move(chA,chC);
Hanoi(n-1,chB,chA,chC);
}
}
public static void main(String[] args)
{
Scanner ss = new Scanner(System.in);
System.out.print("输入塔数:");
int n = ss.nextInt();
HanoiY han=new HanoiY();
han.Hanoi(n,'A','B','C');
}
}