5.16 兔子生兔子,日期时间练习

namespace ConsoleApplication8
{
    class Program
    {
        static void Main(string[] args)
        {
            #region
            //    //有一对幼兔,幼兔一个月后长成小兔,小兔一个月后长成成兔。并生下一对幼兔,
            //// 问几年后,有多少对幼兔,多少对小兔,多少对成兔,兔子总数是多少?
            // //   成兔每月生一对幼兔。
            //    Console.WriteLine("请输入月份");
            //    int MM = int.Parse(Console.ReadLine());
            //    int ct = 0;//成兔初始化
            //    int xt = 0;//小兔初始化
            //    int yt = 1;//幼兔刚开始有一只
            //    int zs = 1;//总数开始一只

            //    for (int i = 1; i <= MM;i++ )
            //    {
            //        if (i== 1)
            //        {
            //            ct = 0;
            //            xt = 0;
            //            yt = 1;
            //            zs = 1;
            //        }
            //        else
            //        {
            //          ct = ct + xt;
            //           xt =yt ;
            //           yt = ct;
            //            zs = ct + xt + yt;
            //        }
            //    }
            //Console.WriteLine(MM+"个月后"+"\n"+"成兔个数为"+ct+"\n"+"小兔个数为"+xt+"\n"+
            //    "幼兔个数为"+yt+"\n"+"总数为"+zs);
            //Console.ReadLine();
            #endregion
            #region
            ////显示时间,显示,日、月、时、分、秒。
            //DateTime dt = DateTime.Now;
            //Console.WriteLine(dt);
            //Console.ReadLine();
            //显示年,月、日、时、分、秒。 

            //DateTime dt = DateTime.Now;
            //string s;
            //s = dt.ToString("yyyy年MM月dd日hh时mm分ss秒");
            //Console.WriteLine(s);
            //Console.ReadLine();
            #endregion

            ////输入一个 日期判断是否正确
            //try catch 异常语句使用
            Console.Write("请输入一个日期");
            string d = Console.ReadLine();
            try
            {
                DateTime dt = new DateTime();
                dt = DateTime.Parse(d);
                Console.Write("输入正确");
            }
            catch
            {
                Console.Write("输入有误");
            }
            Console.ReadLine();

        }
    }
}
时间: 2024-10-18 15:44:30

5.16 兔子生兔子,日期时间练习的相关文章

兔子生兔子函数递归

namespace 兔子生兔子函数递归{    class Program    {        static void Main(string[] args)        {            Console.WriteLine("请输入你想知道兔子哪个月的数量:");            int m = Convert.ToInt32(Console.ReadLine());            int sum = new Program().tuzi(m);  //定

算法:兔子生兔子

古典问题:有一只大兔子,大兔子每个月生一只小兔子,第二个月小兔子会长成大兔子,假如兔子都不死,问第N个月的兔子总数为多少? 解法一.循环 1 public long sumRubbit1(int n){ 2 long total = 0; //兔子总数 3 int big = 1; //大兔子总数 4 int middle = 0; //中兔子总数 5 int little = 0; //小兔子总数 6 if(n==1){ 7 total = big; 8 }else if(n==2){ 9 l

兔子生兔子问题

一对兔子,从出生后的第3个月起每个月都生1对,小兔子长到第3个月后每个月又生1对兔子,假如兔子都不死,某个月的兔子总数是多少分析:每个月兔子总数1,1,2,3,5,8,13,21,34,55... n1=1;//第一个月n2=1;//第二个月 n1=n1+n2;//第三个月 n2=n1+n2;//第四个月 f(n):第n个月 兔子总量 f(n)=f(n-1)+f(n-2) f(5)=f(4)+f(3) f(4):3 f(3):2 f(2):1 f(1):1 <script> function

题四:一对兔子生兔子,给个月份算有几只兔子

这个用递归就行,兔子就是个类,他们有自己的行为,这种思路可以帮助我们给兔子建立模型. 写法一: /** * 有一对兔子,从出生后第三个月起每个月都生一对兔子,小兔子长到第三个月又生一对兔子,假如兔子都不死,问每个月的兔子总数多少? */ public class Test4 { public static void main(String[] args) { RabbitPair rabbitPair = new RabbitPair(6); System.out.println(rabbitP

兔子生兔子问题(斐波那契数列)

一道经典的算法问题. 题目:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子.假如兔子都不死,要求输出一年内兔子的数量是多少. 1 1 2 3 5 8…… 代码如下: //兔子问题(斐波那契) package com.hxzy.homework; public class HomeWork05 {     public static void main(String[] args) {         // TODO Auto-generated meth

古典问题-兔子生兔子

问题描述: 有一兔子,从出生后第3个月起每个月都生一兔子, 小兔子长到第三个月后每个月又生一对兔子 ,假如兔子都不死,问每个月的兔子总数为多少? 问题分析: 月份 兔子数 分析 1 1 f(1)=1 2 1 f(2)=1 3 1+1 f(3)=2 4 1+1  +1 f(4)=3 5 1+1+1  +1+1 f(5)=5 6 1+1+1+1+1 +1+1+1 f(6)=8 7 1+1+1+1+1+1+1+1  1+1+1+1+1 f(7)=13 .... .... ... 总结 1,1,2,3,

C语言经典题目——兔子生兔子

根据本月成兔=上月成兔+上月小兔:本月小兔=上月幼兔:本月幼兔=本月成兔 利用while循环: Console.WriteLine("请输入月份:"); //int m = int.Parse(Console.ReadLine()); //int ct = 0; //int xt = 0; //int yt = 1; //int zt = 1; //int i = 1; //while(i<=m) //{ // if (i == 1) // { // ct = 0; // xt

兔子生兔子

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { int a = 0;//成兔 int b = 0;//小兔 int c = 1;//幼兔 for (in

【Python】【demo实验14】【练习实例】【斐波那契数列】【经典兔子生小兔子问题】

古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? 每个月的兔子数量 1:22:23:4 2+24:6 2+2+25:10 2+2+2+2+26:16 6+6+47:26 10+10+6 第一个月和第二个月兔子不繁殖 第三个月,两个兔子繁殖两个兔子,共四个 第四个月,两个兔子继续繁殖两个兔子,小兔子不繁殖:共6个 以此类推 2,2,4,6,10,16,26 这个数量刚好是斐波那契数列 的两倍 源代码: #