Question: / * MoveTower ( disk , source, dest, spare ) : if disk = = 1 : move disk from source to dest else MoveTower

/*
MoveTower (disk, source, dest, spare):
if disk ==1 :
move disk from source to dest
else
MoveTower (disk -1, source, spare, dest)
move disk from source to dest
MoveTower (disk -1, spare, dest, source)
*/
// Please use appropriate data types and
// also design appropriate output to demonstrate the correctness of your code.
//
// Assume we use characters A, B, C to denote the source, spare, dest, respectively.
// Your output may look as follows:
//------------------------------------
// Please enter the number of disks: 3
// move disk from A to C
// move disk from A to B
// move disk from C to B
// move disk from A to C
// move disk from B to A
// move disk from B to C
// move disk from A to C
//
//=============================================== Note
//
//1. DO NOT DELETE ANY COMMENT!!!
//2. You will only need to fill the block with comments "COMPLETE THIS BLOCK".
//3. Modify the file name to "HanoiTower.java" before compiling it.
//
//===============================================
import java.util.Scanner;
public class HanoiTower {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.print("Please enter the number of disks: ");
int disk = input.nextInt();
// call hanoiTower method
hanoiTower(disk,'A','C','B');
}
public static void hanoiTower(int disk, char source, char dest, char spare){
// choose appropriate data type and update "datatype"
if (disk ==1){
// COMPLETE THIS BLOCK
} else {
// COMPLETE THIS BLOCK
}
}
}

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 Programming Questions!