- package com.cash;
- public class Demo {
- /**
- * 得到斐波那切数列上第num个数是多少
- * @param num 斐波那切数列上第num个数
- * @return
- */
- public static int count(int num){
- if(num==1 || num == 2){
- return 1;
- }else{
- return count(num -1) + count(num -2);
- }
- }
- public static void main(String[] args) {
- int result = count(10);
- System.out.println(result);
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/151120137207.html
来源: http://www.codesnippet.cn/detail/151120137207.html