initial commit

This commit is contained in:
2020-07-02 15:04:13 -05:00
parent 5d9c8ebde6
commit 640ea5a735

28
Recursion/Hanoi.java Normal file
View File

@@ -0,0 +1,28 @@
package Recursion;
import java.util.Scanner;
public class Hanoi {
private static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
System.out.println("Move how many disks from A to C?");
int n = sc.nextInt();
hanoi(n, "A", "B", "C");
}
private static void move(String from, String to) {
System.out.println("Move disc from "+from+" to "+to);
}
private static void hanoi(int number, String from, String helper, String to) {
if(number != 0) {
hanoi(number-1, from, to, helper);
move(from, to);
hanoi(number-1, helper, from, to);
}
}
}