Question: Write a Java program to solve a Towers of Hanoi puzzle given the number of disks. The program should first prompt the user for the

Write a Java program to solve a Towers of Hanoi puzzle given the number of disks. The program should first prompt the user for the number of disks. Then it should display the steps, one per line. Each step should indicate source peg and destination peg (see sample output below). The steps should also be sequentially numbered. In addition, your program should answer the following: By not counting movements, write a recursive module to report how many movements there will be in total.

Sample Output:

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!