📄 hanio2.java
字号:
//import java.io.*;
public class Hanio2
{
static int nDisks;
public static void main(String[] args)
//throws IOException
{
System.out.println("shu:");
nDisks=SavitchIn.readInt();//Integer.parseInt(In());
doTowers(nDisks,'A','B','C');
}
public static void doTowers(int topN,char A,char B,char C)
{
if(topN==1)
System.out.println("Disk 1 from "+A+" to "+C);
else
{
doTowers(topN-1,A,C,B);//把A上的N-1个盘子放到B上
System.out.println("Disk "+topN+" from "+A+" to "+C);
doTowers(topN-1,B,A,C);//把B那个的N-1个盘子放到c上
}
}
/*public static String In() throws IOException
{
String str;
BufferedReader Input=new BufferedReader(new InputStreamReader(System.in));
//数据流进行输入
str=Input.readLine();//读取行。
return str;
}*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -