In the Towers of Hanoi program, declare a new variable called
moveCountand initialize it to zero. Comment out all current print statements, and just after each commented print statement that says “move …” add a statement that increments the
moveCountvariable by 1. Import the Java API
Scannerclass. In the
mainmethod, prompt for and input an integer that asks the user for desired number of disks, and assign it to a new variable called
disks.Then substitute
disksfor 4 as the first argument in
main’s call of the
movemethod. After the
movecall in
main,add a statement that prints the final value of
moveCountand the value of
2disks. Execute the program for progressively increasing values of the disks, and compare the outputs with Wikipedia’s formula. Say how far your computer lets you go toward 64 disks, and if you can’t get that far, describe the problem.
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.