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);
}
}
相关文档:
(一)线程同步
实现生产者消费者问题来说明线程问题,举例如下所示:
/**
* 生产者消费者问题
*/
public class ProducerConsumer {
/**
* 主方法
*/
public static void main(String[] args) {
ProductBox pb = new ProductBox ......
在java对oracle的操作中,日期字段是很头疼的事情,其实仔细研究一下也并不难掌握。
举个例子来说明:
表 book 中有name varchar2(20)//书籍名称,buydate Date //购买日期 两个字段。
已经创建了数据库连接Connection conn;
方法一、使用java.sql.Date实现比较简单的yyyy-mm-dd格式日期。
java.sql. ......
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.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;
import java.util.*;
public class NewArrayList {
public static void main(String[] args) {
List<Student> students = new ArrayList<Student>();
for (int i = 0; i < 6; i++) {
students.add(new Student("Happy"+i,"male" ......