每日编程1
2015-09-01 12:42
204 查看
题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少?
//这是一个菲波拉契数列问题
publicclass lianxi01 {
public static void main(String[] args) {
System.out.println("第1个月的兔子对数: 1");
System.out.println("第2个月的兔子对数: 1");
int f1 = 1, f2 = 1, f, M=24;
for(int i=3; i<=M; i++) {
f = f2;
f2 = f1 + f2;
f1 = f;
System.out.println("第" + i +"个月的兔子对数: "+f2);
}
}
}
//这是一个菲波拉契数列问题
publicclass lianxi01 {
public static void main(String[] args) {
System.out.println("第1个月的兔子对数: 1");
System.out.println("第2个月的兔子对数: 1");
int f1 = 1, f2 = 1, f, M=24;
for(int i=3; i<=M; i++) {
f = f2;
f2 = f1 + f2;
f1 = f;
System.out.println("第" + i +"个月的兔子对数: "+f2);
}
}
}
相关文章推荐
- malloc函数详解
- V4L2编程
- java 自动化测试平台构建思想
- 解决eclipse+MAVEN提示One or more constraints have not been satisfied.的问题
- JNI编程指南-第十一章 JNI设计思想概述
- php获取当月天数及当月第一天及最后一天、上月第一天及最后一天实现方法
- JNI编程指南-第十章 使用JNI时容易出错的地方
- PHP 数组转字符串后仍保留数组格式
- Spring笔记――4.创建Bean的三种方式
- Lua和C++交互详细总结
- java配置自动任务,定期执行代码
- 编程判断两个链表是否相交
- Python--迭代器
- JNI编程指南-第九章 使用己有的本地库
- python bug
- java 克隆的浅拷贝与深拷贝
- Python实现身份证号码解析
- Cglib 与 JDK动态代理的运行性能比较
- Item 20:传递常量引用比传值更好 Effective C++笔记
- python2.7学习笔记(7) ——函数式编程