java 小程序-- 汉诺塔
1.code
public static void main(String[] args) { int level = 4; moveDish(4, 'A', 'B', 'C'); } public static void moveDish(int level, char from, char inter, char to){ if(level==1){ System.out.println("从" + from + "移动" + level + "号盘到" + to ); }else{ moveDish(level-1, from, to, inter); System.out.println("从" + from + "移动" + level + "号盘到" + to ); moveDish(level-1, inter, from, to); } }
2. 效果图