码迷,mamicode.com
首页 > 其他好文 > 详细

奶牛问题

时间:2015-04-28 20:55:09      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:

 1 public class Test {
 2     private static int sum=1;
 3     private static void giveBirth(int year)
 4     {
 5         if(year>3)
 6             sum+=year-3;
 7         for(year=year-3;year>0;year--)
 8         {
 9             giveBirth(year);
10         }
11     }
12     public static void main(String[] args)
13     {
14         System.out.println("please input years:");
15         Scanner scanner=new Scanner(System.in);
16         int year=Integer.parseInt(scanner.nextLine());
17         giveBirth(year);
18         System.out.println(sum);
19     }
20 }

 

奶牛问题

标签:

原文地址:http://www.cnblogs.com/maydow/p/4463846.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!