import java.util.*;
public class Recursion2 {
// Tower of Hanoi ....
public static void towerOfHanoi(int n, String source, String hepler, String destination) {
if (n == 1) {
System.out.println("Transfer Disk " + n + " From : " + source + " To " + destination);
return;
}
towerOfHanoi(n - 1, source, destination, hepler);
System.out.println("Transfer Disk " + n + " From : " + source + " To " + destination);
towerOfHanoi(n - 1, hepler, source, destination);
}
public static void main(String[] args) {
int n = 2;
towerOfHanoi(n, "Source", "Helper", "Destination");
}
}

0 Comments