Tower of Hanoi
import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
static void towerOfHanoi(int n, char from_rod, char to_rod, char aux_rod)
{
if (n == 1)
{
System.out.println("1:" + from_rod + "->" + to_rod);
return;
}
towerOfHanoi(n-1, from_rod, aux_rod, to_rod);
System.out.println(n + ":" + from_rod + "->" + to_rod);
towerOfHanoi(n-1, aux_rod, to_rod, from_rod);
}
// Driver method
public static void main(String args[])
{ Scanner sc=new Scanner(System.in);
int n = sc.nextInt();
towerOfHanoi(n, 'A', 'C', 'B'); // A, B and C are names of rods
}
}