java:递归:汉罗塔游戏计算出最少的步数
package game;
public class HanTa {
public static int i = 0;
public static void main(String[] args){
calc('A', 'B', 'C', 2);
System.out.println("最少需要"+i+"步。");
}
//汉罗塔游戏计算
public static void calc(char src, char ilde, char dest, int num){
if(num == 1){
i++;
System.out.println(src+"-->"+dest);
return;
}
calc(src, dest, ilde, num - 1);
i++;
System.out.println(src+"-->"+dest);
calc(ilde, src, dest, num - 1);
}
}
相关文档:
List的用法
List包括List接口以及List接口的所有实现类。因为List接口实现了Collection接口,所以List接口拥有Collection接口提供的所有常用方法,又因为List是列表类型,所以List接口还提供了一些适合于自身的常用方法,如表1所示。
表1 List接口定义的常用方法及功能
从表1可以看出,List接口提供的适合于自身的 ......
中国公历算法不是太难,关键是星期值的确定。这里给出了简单算法:
public static int dayOfWeek(int y, int m, int d) {
int w = 1; // 公历一年一月一日是星期一,所以起始值为星期日
y = (y-1)%400 + 1; //&n ......
public class Split{
public static void main(String[] args){
double pai = 3.14159;
findTwo(pai);
public static void findTwo(double value){
System.out.println(new DecimalFormat("0.##"). ......
package arrays.compara;
import java.util.Arrays;
public class Student {
public static void main(String[] args) {
Stu[] stus = new Stu[]{
new Stu(156,34,"ad"),
new Stu(153,24,"cc"),
new Stu(126,37,"ab"),
......