public class Testany {

    public static void main(String[] args) {
int value = number(10);
System.out.println(value);
} public static int number(int k){
int value = 0;
int a = 1;
int b = 1;
for(int i =1; i<=k;i++){
value= a+b;
a = b;
b= value;
}
return value; }
}

  

public static void main(String[] args) {
int value = Fun(10);
System.out.println(value);
} public static int Fun(int k){
int arr[] = new int[k];
arr[0] = arr[1] = 1;
for (int i = 2; i < arr.length; i++) {
arr[i] = arr[i - 1] + arr[i - 2];
}
return arr[k-1];
}

  

最简单写法

public static void main(String[] args) {
System.out.println(getFibo(10));
} private static int getFibo(int i) {
if (i == 1 || i == 2)
return 1;
else
return getFibo(i - 1) + getFibo(i - 2);
}

  

最新文章

  1. bash 语法使用
  2. 丹佛机场行李系统Postmortem
  3. CSS实现兼容性的渐变背景(gradient)效果
  4. coreseek实战(三):全文搜索在php中应用(使用api接口)
  5. [LintCode] Implement Trie 实现字典树
  6. ligerui ligerTip气泡提示信息
  7. 【MySQL】MySQL的group_concat使用例子
  8. [LeetCode#12] Roman to Integer
  9. Linq无聊练习系列4--join练习
  10. lesson - 11 课程笔记
  11. Linux 常用命令 (common commands for linux)
  12. luogu1345 奶牛的电信 (最小割)
  13. 基于URL的权限管理(三)
  14. es6proxy
  15. 一个讲课截屏 清明DAY2
  16. RabbitMQ fanout类型的Exchange
  17. 102/107. Binary Tree Level Order Traversal/II
  18. 雷林鹏分享:Ruby 循环
  19. Spring Boot(一):初步认识
  20. BAPC 2014 Preliminary

热门文章

  1. [lodop]css样式after、before添加content内容之前和之后
  2. 前端研究CSS之文字与特殊符号元素结合的浏览器兼容性总结
  3. 最简单的策略模式代替if-else实战
  4. 【C/C++开发】malloc,calloc和realloc的区别和注意事项
  5. beyond Compare 30天过期后的处理办法
  6. PHP使用glob方法遍历文件夹下所有文件
  7. [转帖]一文尽懂 USB4
  8. java当中JDBC当中的transaction例子
  9. 共阳极RGB LED二极管
  10. python 之 面向对象基础(继承与派生,经典类与新式类)