import java.util.Scanner;
public class Principal{
public static void main(String [] args){
int num=0;
Scanner leer= new Scanner (System.in);
Hanoi h= new Hanoi();
System.out.println ("ingrese el numero de aros");
num = leer.nextInt();
h.Hanoi(num, 1,2,3,);
}
}
Public class Hanoi{
public void Hanoi( int n, int inicio,int temp, int fin ){
if( n==1){
System.out.println ("moviendo de la torre 1 a la torre 3");
}
else{
Hanoi(n-1, inicio, fin, temp );
System.out.println ("moviendo de la torre de inicio"+inicio+"a la torre de destino"+fin);
Hanoi(n-1, temp, inicio, fin );
}
}
No comments:
Post a Comment