import java.util.Scanner; public class TowersOfHanoi { private int count = 0; public void solve(int n, String start, String auxiliary, String end) { if (n == 1) { count++; System.out.println(count + " " + start + " -> " + end); return; } else { solve(n - 1, start, end, auxiliary); count++; System.out.println(count + " " + start + " -> " + end); solve(n - 1, auxiliary, start, end); } return; } @SuppressWarnings("resource") public static void main(String[] args) { TowersOfHanoi towersOfHanoi = new TowersOfHanoi(); System.out.print("Enter number of discs: "); Scanner scanner = new Scanner(System.in); int discs = scanner.nextInt(); towersOfHanoi.solve(discs, "A", "B", "C"); } }