首页 > 其他 > 详细

奶牛问题

时间:2015-04-28 20:55:00      阅读:229      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!