我无法找到一种方法打印我的“河内之塔”计划中的每个步骤。
这是我到目前为止所拥有的:
public static void moveDisksStatus (int n) {
count++;
if (n ==1) {
System.out.println("The original position: " + disks[n-1] + " _ " +" _ ");
System.out.println("Move disk a from " + fromTow + " to " + toTow + ": " + " _ " + disks[n-1] + " _ " );
System.out.println("The total cost is: " + count);
} else {
System.out.println("The original position: " + disks[n-1] + " _ " +" _ ");
System.out.println("Move disk " + disks[n-1] + " from " + fromTow + " to " + toTow + ": " + " _ " + disks[n-1] + " _ ");
towersOfHanoi(n - 1, tempTow, toTow, fromTow, disks);
System.out.println("The total number of moves is: " + count);
}
}
我的输出的前几行:
原始位置:c _ _
将磁盘c从A移到B:_ c _
所需的输出: 原始位置:abc _ _ _
将磁盘a从A移至B:_ bc / _ _ a / _ _ _
基本上,我正在尝试获取用于打印每次移动的环及其位置的方法。此外,根据该方法调用了多少个环,请留空下划线。