题解 | #数字颠倒#
统计每个月兔子的总数
http://www.nowcoder.com/practice/1221ec77125d4370833fd3ad5ba72395
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
//不死神兔,即是斐波那契数列
// 方法一:递归
// Scanner sc = new Scanner(System.in);
// while (sc.hasNext()){
// int month = sc.nextInt();
//
// HJ37 hj37 = new HJ37();
// int qu = hj37.quantity(month);
// System.out.println(qu);
// }
// }
//
// public int quantity(int n){
//// int sum = 1;
// if(n == 1 || n == 2) {
// return 1;
// }
// return quantity(n-1) + quantity(n-2);
// 方法二:交替前进
Scanner sc = new Scanner(System.in);
while (sc.hasNext()){
int in = sc.nextInt();
int a = 1,b = 1, sum;
for(int i=1; i<in; i++){
sum = a+b;
a = b;
b = sum;
}
System.out.println(a);
}
}
}