题解 | #统计每个月兔子的总数#
统计每个月兔子的总数
http://www.nowcoder.com/practice/1221ec77125d4370833fd3ad5ba72395
import java.util.; import java.io.; public class Main{ public static void main(String[] args)throws IOException{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String str = null; while((str = in.readLine()) != null){ int sum = 1; int pre = 1; int next = 1; int num = Integer.parseInt(str); if(num >= 3){ for(int i = 3;i <= num;i ++){ sum = pre + next; pre = next; next = sum; } } System.out.println(sum); } } }
我居南半坡 文章被收录于专栏
多刷题,积蓄力量,欢迎讨论