(int n, char from_rod, char to_rod, char helper_rod)
| 1 | package com.JournalDev; |
| 2 | public class Main { |
| 3 | static void towerOfHanoi(int n, char from_rod, char to_rod, char helper_rod) |
| 4 | { |
| 5 | if (n == 1) |
| 6 | { |
| 7 | System.out.println("Take disk 1 from rod " + from_rod + " to rod " + to_rod); |
| 8 | return; |
| 9 | } |
| 10 | towerOfHanoi(n-1, from_rod, helper_rod, to_rod); |
| 11 | System.out.println("Take disk " + n + " from rod " + from_rod + " to rod " + to_rod); |
| 12 | towerOfHanoi(n-1, helper_rod, to_rod, from_rod); |
| 13 | } |
| 14 | |
| 15 | public static void main(String args[]) |
| 16 | { |