📄 hanio.java
字号:
public class Hanio
{
public static int count;
public static void Demo(String from,String spare,String to,int n)
{
if(n==1)
{
System.out.println("disk1"+"\t"+from+"\t"+"-->"+"\t"+to);
count++;
}
else
{
Demo(from,to,spare,n-1);
System.out.println("disk"+n+"\t"+from+"\t"+"-->"+"\t"+to);
count++;
Demo(spare,from,to,n-1);
}
}
public static void main(String[] args)
{
System.out.println("Please enter the number of disks.");
int diskn=3;
diskn=SavitchIn.readLineInt();
String from,to,spare;
from="I";
spare="II";
to="III";
Demo(from,spare,to,diskn);
System.out.println("You should take at least "+count+" steps.");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -