易截截图软件、单文件、免安装、纯绿色、仅160KB

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);
 }
}


相关文档:

Java中集合容器类List和Set的用法

List的用法
List包括List接口以及List接口的所有实现类。因为List接口实现了Collection接口,所以List接口拥有Collection接口提供的所有常用方法,又因为List是列表类型,所以List接口还提供了一些适合于自身的常用方法,如表1所示。
表1  List接口定义的常用方法及功能
从表1可以看出,List接口提供的适合于自身的 ......

用Java操作Oracle日期类型字段

在java对oracle的操作中,日期字段是很头疼的事情,其实仔细研究一下也并不难掌握。
举个例子来说明:
表 book    中有name varchar2(20)//书籍名称,buydate Date //购买日期 两个字段。
已经创建了数据库连接Connection conn;
方法一、使用java.sql.Date实现比较简单的yyyy-mm-dd格式日期。
java.sql. ......

java:二分查找法

package arrays.compara;
/**
 *
 * @author Happy 二分查找法
 */
public class BinarySearch {
 public static void main(String[] args) {
  int[] arrInt = { 2, 34, 32, 24, 23, 34, 12, 3, 4, 2 };
  int index = bSearch(29, arrInt, 0, arrInt.length);
 & ......

java:Set循环遍历的俩种方法使用

package collection;
import java.util.*;
public class NewSet {
 public static void main(String[] args) {
  Set<Student> students = new HashSet<Student>();
  for (int i = 0; i < 6; i++) {
   students.add(new Student("Happy"+i,"male"+i,20+i)) ......

java:递归:上楼梯每次只能一步或者两步,有多少走法

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 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号