import java.util.*;
public class Hanoi {
void shift(String s, String aux, String t, int n, int m)
{
    if(n==1)
        System.out.println("Shift the disc"+m+" from"+s+" to "+t);
    else
    {
        shift(s,t,aux,n-1,1);
        shift(s,aux,t,1,n);
        shift(aux,s,t,n-1,1);
    }
}
public static void main(String args[])
{
    Hanoi x=new Hanoi();
    Scanner src=new Scanner(System.in);
    System.out.println("Enter source name : ");
    String sc=src.next();
    System.out.println("Enter target name: ");
    String tgt=src.next();
    System.out.println("Enter number of dics : ");
    int n=src.nextInt();
    x.shift(sc,"aux",tgt,n,1);
}
}

Output:-

Enter source name : 
A
Enter target name: 
B
Enter number of dics : 
Shift the disc1 from A to B
Shift the disc2 from A to aux
Shift the disc1 from B to aux
Shift the disc3 from A to B
Shift the disc1 from aux to A
Shift the disc2 from aux to B
Shift the disc1 from A to B