From 640ea5a735229610508efdce68539dbb91b17681 Mon Sep 17 00:00:00 2001 From: Eugene Fischer Date: Thu, 2 Jul 2020 15:04:13 -0500 Subject: [PATCH] initial commit --- Recursion/Hanoi.java | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Recursion/Hanoi.java diff --git a/Recursion/Hanoi.java b/Recursion/Hanoi.java new file mode 100644 index 0000000..3cb4137 --- /dev/null +++ b/Recursion/Hanoi.java @@ -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); + } + + } + +} \ No newline at end of file