Question: Write a Java program to solve a Towers of Hanoi problem recursively given the number of disk. At your last move the all the disks
-
Write a Java program to solve a Towers of Hanoi problem recursively given the
number of disk. At your last move the all the disks must be on the last peg. Your program must:
-
- prompt the user for the number of disks.
-
- display the steps, one per line.
-
- indicate the source peg the destination peg (see sample below) for each step.
-
- sequentially number the steps.
-
- include a recursive module which reports the total movement.
-
- print results as below (here is just an example for 3 disks and 0 disks):
-
How many disks? (0 to end) 3
1: 1 to 3 2: 1 to 2 3: 3 to 2
4: 1 to 3
5: 2 to 1
6: 2 to 3
7: 1 to 3
Total Moves: 7
How many disks? (0 to end) 0
Total Moves: 0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
