📄 t4_10.java
字号:
//题目4.10
public class T4_10 {
private static int sumMoves=0;
public static void main(String[] args)
{
System.out.println("Enter number of Disks");
int n =MyInput.readInt();
System.out.println("The moves are:");
moveDisks(n,'A','B','C');
System.out.println("The sum of moves is "+sumMoves);
System.exit(0);
}
public static void moveDisks(int n ,char fromT,char toT,char auxT){
if(n==1){
System.out.println("move disk "+n+"from "+fromT+"to "+toT);
sumMoves++;
}
else{
moveDisks(n-1,fromT,auxT,toT);
System.out.println("move disk "+n+"from "+fromT+"to "+toT);
sumMoves++;
moveDisks(n-1,auxT,toT,fromT);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -