java:递归:10元钱按1,2,5元任意组合
package game;
public class Money {
public static void main(String[] args) {
fun("", 10);
System.out.println("总共算法:" + i);
}
// 10元钱的组成,1,2,5任意组合
public static int i = 1;
public static void fun(String log, int n) {
// int num = n;
if (0 == n) {
System.out.println(log.substring(0, log.length() - 1) + "=");
return;
} else if (1 == n) {
System.out.println(log + "1" + "=");
return;
}
if (n >= 1)
fun(log + "1+", n - 1);
if (n >= 2)
fun(log + "2+", n - 2);
if (n >= 5)
fun(log + "5+", n - 5);
i++;
}
}
相关文档:
(一)线程同步
实现生产者消费者问题来说明线程问题,举例如下所示:
/**
* 生产者消费者问题
*/
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. ......
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);
& ......
package arrays.myArray;
import java.util.Scanner;
public class SortObject {
private static int intercePosition = 0; // 记录单个运算数据的长度
private static int[] intercePositionIndex = null; // 记录“(”的下标
private static int[] intercePositionEnd = null; // 记录 ......
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)) ......