给出一个数字 3 需要打打印出右边效果
这个例子 但是不知道怎么打印数字
public class SolveTowers
{
public static void main(String[] args)
{
TowersOfHanoi tower=new TowersOfHanoi(3);
tower.solve();
}
}
class TowersOfHanoi
{
private int totalDisk;
public TowersOfHanoi(int disks)
{
totalDisk=disks;
}
public void solve()
{
moveTower(totalDisk,'A','B','C');
}
private void moveTower(int numDisks,char start,char end,char temp)
{
if(numDisks==1)
moveOneDisk(start,end);
else
{
moveTower(numDisks-1,start,temp,end);
moveOneDisk(start,end);
moveTower(numDisks-1,temp,end,start);
}
}
private void moveOneDisk(char start,char end)
{
System.out.println("move one disk from "+start+"to "+end);
System.out.println();
}
}
----------------解决方案--------------------------------------------------------