|
//Towers of Hanoy CLASS -->> Write BY Ali Asadiyan public class Honoy { public void Tower(int n , String a,String b, String c){ if (n==1)System. out.println("Move Disk No:"+n+" From Column "+a+" to "+c); else {Tower (n-1 , a ,c ,b); System. out.println("Move Disk No:"+n+" From Column "+a+" to "+c);Tower (n-1 , b ,a ,c); } } } |
|
//Towers of Hanoy Main CLASS -->> Write BY Ali Asadiyan import java.util.Scanner;public class TestHanoy { public static void main(String[] args) {Scanner Input = new Scanner(System.in);Honoy TheHonoy = new Honoy();System. out.println("How many disks do you want to move?:"); int n = Input.nextInt();TheHonoy.Tower(n, "First", "Help ", "End ");} } |