- /**
- * 获得N年后羊总数量
- * @param year 多少年
- * @return
- */
- public static long getTotalCountByYear(int year){
- if(year%2!=0) year--;
- long _1thCount = 2;// 第6年增长数量
- long _2thCount = 4;// 第8年增长数量
- long _3rdCount = _2thCount+_1thCount;// 第10年增长数量
- long totalCount = _1thCount+_2thCount+_3rdCount;
- System.out.print(_1thCount+","+_2thCount+","+_3rdCount+",");
- for(int i=12;i<=year;i=i+2){
- _1thCount = _2thCount;
- _2thCount = _3rdCount;
- _3rdCount = _2thCount+_1thCount;
- totalCount = totalCount + _3rdCount;
- System.out.print(_3rdCount+",");
- }
- return 1+1+2+totalCount;
- }
- //该片段来自于http://www.codesnippet.cn/detail/021220137662.html
来源: http://www.codesnippet.cn/detail/021220137662.html