java:递归汉罗塔游戏最少的走法
package game;
public class HanTaGame {
public static void main(String[] args) {
fun('1', '2', '3', 2);
}
// 汉塔游戏解决方案
public static void fun(char src, char idle, char dest, int n) {
if (1 == n) {
System.out.println(src + "--->" + dest);
return;
}
//定义一个顺序
fun(src, dest, idle, n - 1);
System.out.println(src + "--->" + dest);
//进行顺序的交换
fun(idle, src, dest, n - 1);
}
}
相关文档:
package arrays.file;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamRea ......
package arrays.myArray;
public class SortArr {
public static void main(String[] args) {
int[] arrInt = { 4, 7, 8, 5, 6, 3, 2, 3, 4 };
maoPaoSort(arrInt);
print("冒泡排序:", arrInt);
arrInt = new int[]{ 4, 7, 8, 5, 6, 3, 2, 3, 4 };
& ......
package collection;
public class Student {
public Student() {}
public Student(String name, String sex, int age) {
this.name = name;
this.sex = sex;
this.age = age;
}
@Override
public String toString() {
......
package floatt;
public class Go {
public static int i = 0;
public static void main(String[] args){
calc("", 5);
System.out.println("总共有"+i+"种走法~");
}
//上楼梯每次只需一步或者两步,有多少走法
public static void calc(String lo ......
package game;
public class JieCeng {
public static void main(String[] args){
System.out.println(fun(10));
}
public static int fun(int n){
if(1==n)
return 1;
System.out.println( n * fun(n-1));
return ......